合成图像双字号文本仅显示其一及annotate与caption兼容性咨询
问题描述
我需要在合成图像中展示两种不同字号的文本,但实际仅第一个文本能够显示。所使用的ImageMagick命令如下:
convert \( -resize "1000x1000^" -blur 50x5 "https://example.com/origin.jpg" -extent 1000x1000 -background none -fill "yellow" -colorize 40 \) \ \( -font /var/hoge.otf -annotate +0-250 -background none -fill white -pointsize 80 -size 850x caption:"First line text in large font size" \) \ \( -font /var/hoge.otf -annotate +0+250 -background none -fill white -pointsize 60 -size 850x caption:" Second line of text in small font size" \) \ -gravity center -compose over -composite /var/output.jpg
请问annotate选项与caption选项是否无法同时使用?
解答
annotate和caption不能同时在同一个操作单元(括号内)使用,这就是你只看到第一个文本的原因——caption是生成包含文本的新图像的指令,annotate是在已有图像上叠加文本的指令,两者在同一个括号里会互相干扰,导致第二个文本的操作失效。
你可以通过以下两种方式修正命令:
方式1:用caption生成独立文本层再合成
分别用caption生成两个不同字号的文本图像,再依次与背景图合成:
convert \( -resize "1000x1000^" -blur 50x5 "https://example.com/origin.jpg" -extent 1000x1000 -background none -fill "yellow" -colorize 40 \) \ \( -font /var/hoge.otf -background none -fill white -pointsize 80 -size 850x caption:"First line text in large font size" \) \ -gravity center -geometry +0-250 -composite \ \( -font /var/hoge.otf -background none -fill white -pointsize 60 -size 850x caption:"Second line of text in small font size" \) \ -gravity center -geometry +0+250 -composite /var/output.jpg
方式2:直接用annotate在背景图上叠加两次文本
去掉caption指令,直接在处理好的背景图上先后添加两个不同字号的文本:
convert \( -resize "1000x1000^" -blur 50x5 "https://example.com/origin.jpg" -extent 1000x1000 -background none -fill "yellow" -colorize 40 \) \ -font /var/hoge.otf -fill white -pointsize 80 -gravity center -annotate +0-250 "First line text in large font size" \ -font /var/hoge.otf -fill white -pointsize 60 -gravity center -annotate +0+250 "Second line of text in small font size" \ /var/output.jpg
两种方式都能让两个不同字号的文本正常显示,可根据需求选择。
内容的提问来源于stack exchange,提问作者user3474300
相关产品推荐
相关产品推荐

