Search code examples
imagemagickbatch-processingimagemagick-convert

Imagemagick convert and compose batch of files


I am trying to make a fast convert of a batch of files like this:

convert ./src/*.png -set filename: '%t' -gravity West -draw 'image over 0,0 424,600 "./panel.png"' ./dest/%[filename:].png

which is pretty similar to COMPOSITE:

convert ./src/*.png ./panel.png -set filename: '%t' -gravity +0+0 -composite ./dest/%[filename:].png

except the last one is not working and just making one first crappy-looking file. Looks like it's bug?

Does anybody know how to make it more correct with -composite? for|awk|ls|find for each file in shell is not acceptable - because that is slower than the first example.


Solution

    • Read in the list of files,
    • set their output filenames,
    • include the IM special image placeholder "null:",
    • read in your overlay image,
    • optionally, set the geometry,
    • and composite that overlay onto all the other images with "-layers composite".

    That null: separates the original input file list from the overlay image so ImageMagick knows where in the stack you want to start doing the composite.

    Try something like this (one step per line for readability):

    convert ./src/*.png \
        -set filename: '%t' \
        null: \
        ./panel.png \
        -layers composite ./dest/%[filename:].png