Numbering/Labeling images (eg 1,2,3 or A,B,C) with ImageMagick montage

巧了我就是萌 提交于 2019-12-12 10:18:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!