目前,我正在开展一项非常全面的(至少对我而言)图像作业。我想添加一些我从exif数据中提取的注释并添加叠加图像。 目前我有以下代码:
convert -verbose source.jpg \
-pointsize 32 -fill white -undercolor '#00000070' -gravity NorthWest -annotate +10+10 "some exif data"\
-pointsize 32 -fill white -undercolor '#00000070' -gravity North -annotate +10+10 "more exif data"\
-pointsize 32 -fill white -undercolor '#00000070' -gravity NorthEast -annotate +10+10 "even more exif data"\
-gravity South overlay.png \
-layers flatten \
-quality 95 destination.jpg;
注释工作正常,包括位置。但我坚持使用叠加层。它似乎是" -gravity South"在这里工作不起作用。它卡在左上角。我需要更改什么才能将叠加层置于底部并居中?
奖金问题:如何让叠加半透明?
答案 0 :(得分:2)
您应该-composite
使用-flatten
而不是convert
:
convert -verbose source.jpg \
-pointsize 32 -fill white -undercolor '#00000070' -gravity NorthWest -annotate +10+10 "some exif data"\
-pointsize 32 -fill white -undercolor '#00000070' -gravity North -annotate +10+10 "more exif data"\
-pointsize 32 -fill white -undercolor '#00000070' -gravity NorthEast -annotate +10+10 "even more exif data"\
-gravity South overlay.png -composite \
result.jpg
如果您希望叠加层是半透明的,请使用:
convert -verbose source.jpg \
-pointsize 32 -fill white -undercolor '#00000070' -gravity NorthWest -annotate +10+10 "some exif data"\
-pointsize 32 -fill white -undercolor '#00000070' -gravity North -annotate +10+10 "more exif data"\
-pointsize 32 -fill white -undercolor '#00000070' -gravity NorthEast -annotate +10+10 "even more exif data"\
\( -gravity South overlay.png -channel A -fx "0.5" \) -composite \
result.jpg
顺便说一下,-pointsize
,-fill
和-undercolor
是“settings”,因此它们会保持设置直到更改为止,因此您不需要重复一遍:
convert -verbose source.jpg -pointsize 32 -fill white -undercolor '#00000070' \
-gravity NorthWest -annotate +10+10 "some exif data"\
-gravity North -annotate +10+10 "more exif data"\
-gravity NorthEast -annotate +10+10 "even more exif data"\
\( -gravity South overlay.png -channel A -fx "0.5" \) -composite \
result.jpg
答案 1 :(得分:1)
您需要使用composite
而不是convert
添加叠加层。
convert -verbose source.jpg \
-pointsize 32 -fill white -undercolor '#00000070' -gravity NorthWest -annotate +10+10 "some exif data"\
-pointsize 32 -fill white -undercolor '#00000070' -gravity North -annotate +10+10 "more exif data"\
-pointsize 32 -fill white -undercolor '#00000070' -gravity NorthEast -annotate +10+10 "even more exif data"\
-layers flatten \
-quality 95 destination.jpg;
然后:
composite -gravity South overlay.png destination.jpg result.jpg
有关composite
here的更多信息。
编辑:最好的方法是使用ImageMagick中间保存格式miff
和流水线操作。这将节省磁盘读/写的额外步骤。
convert -verbose source.jpg \
-pointsize 32 -fill white -undercolor '#00000070' -gravity NorthWest -annotate +10+10 "some exif data"\
-pointsize 32 -fill white -undercolor '#00000070' -gravity North -annotate +10+10 "more exif data"\
-pointsize 32 -fill white -undercolor '#00000070' -gravity NorthEast -annotate +10+10 "even more exif data"\
-layers flatten \
-quality 95 miff:- | \
composite -gravity South overlay.png miff:- destination.jpg