[Solved, use shell to loop] Loop/Repeat/For in ImageMagick?
Posted: 2018-09-17T14:30:14-07:00
Linux x64: ImageMagick 6.8.8-1 Q16
I need to read a raw image and split it into 16 pieces.
I need to overlay pieces 1 and 2, 3 and 4, etc. and tweak and label each group.
Then I need to convert everything into 1 final output image.
I wrote a bash script to do it but it runs a bit slow.
The single command below "works", needs no temporary files and is faster than the bash script, but I had to use the clone commands exactly the right number of times and hardcode the section names.
Is there a better way to loop in ImageMagick? Or a better way to do this?
(The real version is bigger and has more than the 8 sections in my example)
annotate="-gravity north -stroke #FFFF -fill white -strokewidth 1 -pointsize 15 -annotate 0"
bright="-brightness-contrast 50x50 -black-threshold 20%"
convert \
-size 512x2048 cmyk:test.raw -set colorspace Gray -separate -average -normalize -crop 512x256 +repage \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 1" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 2" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 3" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 4" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 5" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 6" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 7" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 8" \) -delete 0 \
-append output.png
I need to read a raw image and split it into 16 pieces.
I need to overlay pieces 1 and 2, 3 and 4, etc. and tweak and label each group.
Then I need to convert everything into 1 final output image.
I wrote a bash script to do it but it runs a bit slow.
The single command below "works", needs no temporary files and is faster than the bash script, but I had to use the clone commands exactly the right number of times and hardcode the section names.
Is there a better way to loop in ImageMagick? Or a better way to do this?
(The real version is bigger and has more than the 8 sections in my example)
annotate="-gravity north -stroke #FFFF -fill white -strokewidth 1 -pointsize 15 -annotate 0"
bright="-brightness-contrast 50x50 -black-threshold 20%"
convert \
-size 512x2048 cmyk:test.raw -set colorspace Gray -separate -average -normalize -crop 512x256 +repage \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 1" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 2" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 3" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 4" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 5" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 6" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 7" \) -delete 0 \
\( -clone 0 -crop 512x128 +repage -compose Plus -composite $bright $annotate "Section 8" \) -delete 0 \
-append output.png