Label each panel in a montage
Posted: 2018-07-10T11:54:56-07:00
Version: ImageMagick 7.0.7-39 Q16 x86_64 2018-06-11
EDIT: Platform macOS
I'd like to use the montage command to create a single image where each panel has its own different text label.
I'm more familiar with the -draw "text.." command than the -label command, but I dismissed the -label command as not for me because the examples site showed the results as a sort of extra panel at the bottom. I will use -draw or -label or whatever is recommended. What I want is shown here with both an incorrect and a correct result in the two different images:
https://imgur.com/a/5E46bFP
EDIT: Although my boiled-down code examples below use xc:color, in real life I am doing this with image files as input, not just xc:color. I think that should not change the answer though.
Here's what I tried (in bash shell script form):
I can get the results I want by first using convert to make temporary labeled images, and then using montage to combine those temporary images, like this:
So yes I will do that in the meantime. But my question is, can this be done with montage alone? And how?
EDIT: Platform macOS
I'd like to use the montage command to create a single image where each panel has its own different text label.
I'm more familiar with the -draw "text.." command than the -label command, but I dismissed the -label command as not for me because the examples site showed the results as a sort of extra panel at the bottom. I will use -draw or -label or whatever is recommended. What I want is shown here with both an incorrect and a correct result in the two different images:
https://imgur.com/a/5E46bFP
EDIT: Although my boiled-down code examples below use xc:color, in real life I am doing this with image files as input, not just xc:color. I think that should not change the answer though.
Here's what I tried (in bash shell script form):
Code: Select all
# bad result
montage -geometry 200x200 -gravity center -stroke none -fill white -pointsize 48 \
xc:blue -draw 'text 0,0 "Panel 1"' \
xc:red -draw 'text 0,0 "Panel 2"' \
xc:yellow -draw 'text 0,0 "Panel 3"' \
xc:purple -draw 'text 0,0 "Panel 4"' \
xc:green -draw 'text 0,0 "Panel 5"' \
xc:black -draw 'text 0,0 "Panel 6"' \
-mode concatenate -tile 3x2 using-montage-alone.jpg
Code: Select all
# good result
spec="-geometry 200x200 -gravity center -stroke none -fill white -pointsize 48"
for color in {blue,red,yellow,purple,green,black}; do
panel_number=$((panel_number + 1))
text_spec="text 0,0 'Panel "$panel_number"'"
convert xc:$color $spec -draw "$text_spec" panel-$panel_number.jpg
done
montage panel-{1..6}.jpg -mode concatenate -tile 3x2 resorting-to-convert-first-then-montage.jpg