ImageMagick convert composite many crops from the same image?

22 Views Asked by At

I have a fairly complicated crop-rotate-splice command, here simplified just to crop:

magick "$INPUT" -crop "$WIDTH"x"$HEIGHT" "$DESTINATION"

I would like to cut out many parts of the same $INPUT image, and then finally lay them all on top of each other using convert -composite.

How can I do this without using temporary files?

I think I should be able to

convert \( "$INPUT" -crop ... \) \( "$INPUT" -crop ... \) \( "$INPUT" -crop ... \) \( "$INPUT" -crop ... \) -composite "$DESTINATION"

But is there a way that can also avoid having to repeat the input image path for every cropping?

1

There are 1 best solutions below

4
GeeMack On

If you want to use a particular image several times in an ImageMagick command, you can read it into the command once, store it in an IM memory register "mpr:something" during the command, and recall it when you need it.

magick "$input" -write mpr:img1 +delete \( mpr:img1 ... \) \( mpr:img1 ... \) ... 

Name it "mpr:anyname". You can write to and read from as many of these memory stored images as you want. They exist until the end of the command.