Search code examples
graphicsmagick

GraphicsMagic, create new image with another image centered in it


I have an image I1 of size AxB and want to create a bigger image I2 with a solid background of size CxD where C>A and D>B. I need to put I1 in I2 so that upper-left corner of I1 be at X,Y point of I2.

enter image description here

How can I do this with GraphicsMagic tools?


Solution

  • Like this:

    gm convert -size 1200x1000 xc:steelblue -draw 'image over 10,200 600,800 "tux.png"' result.png
    

    where C=1200, D=1000, x=10, y=200

    enter image description here

    Or, less flexible over the positioning:

    gm convert -background steelblue "tux.png" -gravity center -extent 1200x1200 result.png
    

    enter image description here