我有一个长图像source pic,我想向每个子图像添加文本,但是当向书中添加文本时,我失败了,最终的图像和代码:
convert src.jpg -gravity north -pointsize 53 -fill white -annotate +0+520 "I love you,don't leave me " -annotate +0+1146 "Do not be a programmer,ok?" -annotate +0+1772 "fuck u!" -annotate +0+3024 "too simple " -draw 'translate 340,3340 rotate 21 text 0,0 "Javascript Action"' final.jpg
有人可以帮忙吗?谢谢
答案 0 :(得分:0)
在您的示例中,您应该对Imagemagick中的所有文本放置和旋转使用-annotate,而不是对最后一个使用-draw。这将使您的最后文本不会偏离图像。试试这个:
convert src.jpg -gravity north -pointsize 53 -fill white -annotate +0+520 "I love you,don't leave me " -annotate +0+1146 "Do not be a programmer,ok?" -annotate +0+1772 "xxxx x" -annotate +0+3024 "too simple " -gravity north -annotate 21x21+0+3340 "Javascript Action" final1.jpg
请参见https://imagemagick.org/script/command-line-options.php#annotate
请不要在示例中使用俗语。
如果要换行,则需要使用caption:为每个文本创建一个具有透明背景的新图像。然后在所需位置将新的文本图像合成到您的背景图像上。您可以通过-size Wx参数控制何时换行。在这里,我使用图像的整个宽度,即-size 1000x。
convert src.jpg \
-pointsize 53 -background none -fill white -size 1000x \
\( -gravity center caption:"I love you,don't leave me" \) -gravity north -geometry +0+420 -compose over -composite \
\( -gravity center caption:"Do not be a programmer,ok?" \) -gravity north -geometry +0+1046 -compose over -composite \
\( -gravity center caption:"xxxx x" \) -gravity north -geometry +0+1672 -compose over -composite \
\( -gravity center caption:"too simple" \) -gravity north -geometry +0+2924 -compose over -composite \
\( -gravity center caption:"Javascript Action" -rotate 21 \) -gravity north -geometry +0+3240 -compose over -composite \
final2.jpg
或者为了使其包裹得比图片的宽度更早,我将-size设置为500x
convert src.jpg \
-pointsize 53 -background none -fill white -size 500x \
\( -gravity center caption:"I love you,don't leave me" \) -gravity north -geometry +0+420 -compose over -composite \
\( -gravity center caption:"Do not be a programmer,ok?" \) -gravity north -geometry +0+1046 -compose over -composite \
\( -gravity center caption:"xxxx x" \) -gravity north -geometry +0+1672 -compose over -composite \
\( -gravity center caption:"too simple" \) -gravity north -geometry +0+2924 -compose over -composite \
\( -gravity center caption:"Javascript Action" -rotate 21 \) -gravity north -geometry +0+3240 -compose over -composite \
final3.jpg
请参见
https://imagemagick.org/Usage/text/#caption https://imagemagick.org/Usage/layers/#convert
添加:
要模糊文本,只需在标题后添加-blur:
convert src.jpg \
-pointsize 53 -background none -fill white -size 500x \
\( -gravity center caption:"I love you,don't leave me" -blur 0x3 \) -gravity north -geometry +0+420 -compose over -composite \
\( -gravity center caption:"Do not be a programmer,ok?" -blur 0x3 \) -gravity north -geometry +0+1046 -compose over -composite \
\( -gravity center caption:"xxxx x" -blur 0x3 \) -gravity north -geometry +0+1672 -compose over -composite \
\( -gravity center caption:"too simple" -blur 0x3 \) -gravity north -geometry +0+2924 -compose over -composite \
\( -gravity center caption:"Javascript Action" -blur 0x3 -rotate 21 \) -gravity north -geometry +0+3240 -compose over -composite \
final4.jpg