Label each panel in a montage

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
taxisaga
Posts: 14
Joined: 2018-07-10T11:13:28-07:00
Authentication code: 1152
Location: Sunnyvale, CA

Label each panel in a montage

Post by taxisaga » 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):

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
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:

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
So yes I will do that in the meantime. But my question is, can this be done with montage alone? And how?

User avatar
fmw42
Posts: 24155
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Label each panel in a montage

Post by fmw42 » 2018-07-10T13:36:05-07:00

In IM 7, you need to preface montage with magick, so

magick montage ....

Try this:

Code: Select all

magick montage \
-gravity center -stroke none -fill white -pointsize 48 \
-size 200x200 \
\( 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
That works for me on IM 7.0.8.5 Q16 Mac OSX Sierra

taxisaga
Posts: 14
Joined: 2018-07-10T11:13:28-07:00
Authentication code: 1152
Location: Sunnyvale, CA

Re: Label each panel in a montage

Post by taxisaga » 2018-07-10T13:56:07-07:00

Thanks! That works great for me too.

User avatar
fmw42
Posts: 24155
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Label each panel in a montage

Post by fmw42 » 2018-07-10T15:51:07-07:00

P.S. I think the issue you had was that you needed to use parentheses to keep the text from accumulating over itself. Also I generally do not recommend using -geometry for resizing in montage, only for spacing.

taxisaga
Posts: 14
Joined: 2018-07-10T11:13:28-07:00
Authentication code: 1152
Location: Sunnyvale, CA

Re: Label each panel in a montage

Post by taxisaga » 2018-07-10T16:13:00-07:00

That parens trick is new to me. Very useful, thanks. And -geometry versus -size always confused me. I'll get it one of these days!

Also btw it seems stuff still works on my system without the magick preface, but I take it things are heading that direction so I'll start updating scripts to use that.

User avatar
fmw42
Posts: 24155
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Label each panel in a montage

Post by fmw42 » 2018-07-10T16:44:18-07:00

Do you have both IM 6 and IM 7 on your system? If so, then leaving off the magick and using just montage would work using IM 6.

About parentheses, see http://www.imagemagick.org/Usage/basics/#parenthesis

Post Reply