问题
I'm using
montage *.tif output.tif
to combine several images to one. I would now like them to be numbered (sometimes 1,2,3 …; somtimes A,B,C …) What possibilities are there to label the single images in the combined? Is there an option to put the label not underneath the picture but eg in the upper left or lower right corner?
Unfortunately I could't really figure out how to use the -label command to achieve that. Thanks for any suggestions.
回答1:
If you want to invest a little more effort you can have more control. If you do it like this, you can label the images "on-the-fly" as you montage them rather than having to save them all labelled and then montage them. You can also control the width, in terms of number of images per line, more easily:
#!/bin/bash
number=0
for f in *.tif; do
convert "$f" -gravity northwest -annotate +0+0 "$number" miff:-
((number++))
done | montage -tile x3 - result.png
It takes advantage of ImageMagick miff
format, which means Multiple Image File Format, to concatenate all the output images and send them into the stdin
of the montage
command.
Or, you can change the script like this:
#!/bin/bash
number=0
for f in *.tif; do
convert "$f" -gravity northwest -fill white -annotate +0+0 "$number" miff:-
((number++))
done | montage -tile 2x - result.png
to get
Or maybe this...
#!/bin/bash
number=0
for f in *.tif; do
convert "$f" -gravity northwest -background gray90 label:"$number" -composite miff:-
((number++))
done | montage -tile 2x - result.png
Or with letters...
#!/bin/bash
number=0
letters="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for f in *.tif; do
label=${letters:number:1}
convert "$f" -gravity northwest -background gray90 label:"$label" -composite miff:-
((number++))
done | montage -tile 2x - result.png
回答2:
What possibilities are there to label the single images in the combined?
Iterate with a for loop.
for INDEX in {A,B,C}; do
convert ${INDEX}.jpg labeled_${INDEX}.jpg
done
Is there an option to put the label not underneath the picture but eg in the upper left or lower right corner?
Try using the -annotate with -gravity
convert rose: -fill white \
-gravity NorthWest -annotate +0+0 "A" \
A.png
convert rose: -fill white \
-gravity SouthEast -annotate +0+0 "B" \
B.png
来源:https://stackoverflow.com/questions/30956736/numbering-labeling-images-eg-1-2-3-or-a-b-c-with-imagemagick-montage