Search code examples
imagemagickimagemagick-convert

How to handle multiple elements with imagemagick cli?


We need to put 'information bar's to thousands of image files. For like a week or so i'm trying to learn imagemagick but i just couldn't figure this many elements out so i wanted to ask for a help here.

I get the idea of '-/+append'ing elements and swapping between them but when it comes to 3x3 matrix cells and text/image mixings, i just can't do it. As an example, i can get the 3 rows appended and a column next to it but i can't get to the next step of 'appending 2 more rows together then put them as a column block again' because when i try, all those append gets right or bottom as a whole image.. Well, you will get the idea when you see my brief image below..

magick.exe -size 150x100 -gravity center caption:"txt2" caption:"txt3" caption:"txt4" \
 -append -size 94x294 xc:white -border 3 -swap 0,1 \
 +append outoutout.jpg

FYI, height/width of rows/columns are there just for example not important.. And here comes MSPaint skills: Final Output Idea


Solution

  • You have to create each section separately using parenthesis processing. Then if you want append them appropriately. Alternately, you can create a background image and compose ... -composite each image into its correct location.

    Here is an example in ImageMagick using the second method.

    Unix Syntax:

    magick -size 400x400 xc:white \
    \( barn.jpg -crop 400x200+0+0 +repage \) \
        -geometry +0+0 -compose over -composite \
    \( -size 100x200 xc:white -shave 5x5 -bordercolor black -border 5 \) \
        -gravity northwest -geometry +0+200 -compose over -composite \
    \( -size 100x200 -background white -gravity center -fill black \
        -font Candice label:"Text1\n\nText2\n\nText3" \) \
        -gravity northwest -geometry +100+200 -compose over -composite \
    \( -size 100x200 -background skyblue -gravity center -fill red \
        -font Arial label:"First_line\n\n\nSecond_line" \) \
        -gravity northwest -geometry +300+200 -compose over -composite \
    result.png
    

    enter image description here

    See for example:

    parenthesis processing

    appending

    convert ... -composite