Search code examples
command-lineimagemagickimagemagick-convert

Add a pattern repeated image as a background of another image using ImageMagick convert


I want to add a pattern repeated image as the background of another image that has spaces around. For example i have the pattern 200x200 and an image 1200x800. I have accomplished to add a background color.

The command i'm using to add a background color

convert -background "#333" -resize 768x450 -gravity Center -extent 768x450

Now i need to add a pattern instead of that color. Some suggest that i should make the pattern as one image with the maximum size then use it to add it as background image.

Is it possible to do it with convert or any other command using ImageMagick ?


Solution

  • Not sure what you mean, but I am guessing it's this. Let's make a 200x200 tile to start off with:

    convert -size 200x200 radial-gradient:red-blue t200x200.png
    

    enter image description here

    And now you want to make a 1200x800 image by tiling that basic unit:

    convert -size 1200x800 tile:t200x200.png BigBoy.png
    

    enter image description here

    If you now want to overlay a fine-art, high-quality, centred portrait over the top of your harmonious, subtle background, you can do this:

    convert -size 1200x800 tile:t200x200.png -gravity center smiley.gif -composite BigBoy.png
    

    enter image description here