Search code examples
graphicsmagick

With Graphicsmagick, how to combine 2 images and text in a certain format?


I need to combine 2 images and a short text into one image, in the format that the first image is at the top spanning a row, and the other image at bottom left, the text at bottom right.

The produced image is 400px * 600px, the input images can be any size, if the first image is less than 400px, it will be centered at the top

Is it possible with Graphicsmagick?


Solution

  • Assuming you already have two images called:

    1. top.png (image at the top spanning a row)
    2. left.png (other image at bottom left)

    first of all you have to create the third missing image (called text.png) containing your text:

    gm convert -size 200x300 xc:#7F0000 -pointsize 80 -font Arial -fill white -draw "text 10,150 'text'" text.png
    

    then you can compose the two images in the bottom part (creating an image called bottom.png):

    gm montage left.png -geometry 200x300+0+0 text.png -tile 2x1 bottom.png
    

    and finally you can compose upper and lower parts with:

    gm montage top.png -geometry 400x300+0+0 bottom.png -tile 1x2 result.png    
    

    the result will be an image called result.png, size: 400x600

    top.png:

    enter image description here

    left.png:

    enter image description here

    result.png:

    enter image description here

    Tested on Windows with GraphicsMagick 1.3.18 2013-03-10 Q8