ImageMagick:文本如何在透明框中自动填充文本

Fly*_*ngV 3 text imagemagick transparent box

  1. 我有一张名为funny-santa.jpg的照片(Google Image it,很可爱)
  2. 我已经能够画一个黄色的盒子ONTO funny-santa.jpg'
  3. 我能把TEXT放进那个黄色的盒子里.("圣诞快乐妈妈和爸爸")
  4. 如何在我创建的黄色框内自动调整文本 - 以编程方式?
  5. 是否可以将下面的文本自动拟合到预定义的空间?

这是在现有图片上绘制TRANSPARENT黄色框的代码.我在文档中添加了"Merry Xmas Mom and Dad"文本.挑战在于:如何在我刚刚创建的Box中自动调整我的'Merry Xmas Mom and Dad'?

  1. 如果我的文字改为"我爱你的妈妈和爸爸"怎么办?任何基于文本维度的"硬编码值"都必须重做.

    转换funny-santa.jpg -strokewidth 0 -fill"rgba(255,215,0,0.5)"-draw"rectangle 0,0 1024,350"-pointsize 30 -fill black -annotate + 67 + 60' Merry Christmas Mom和爸爸'output.jpg

Kur*_*fle 7

您也可以从15个月前看看我的答案:

如果使用正确的方法,文本将自动适合.让我们使用宽270像素,高70像素的盒子.这是我使用的命令,首先是一个简短的文字:

mytext="Cheers\!"

convert                            \
  -background '#0008'              \
  -gravity center                  \
  -fill white                      \
  -size 260x70 caption:"${mytext}" \
   funny-santa.jpg                 \
  +swap                            \
  -gravity south                   \
  -composite                       \
   funny-santa---1.jpg 
Run Code Online (Sandbox Code Playgroud)

结果如下(原始图像在顶部,图像底部有文字):

如果您想将更长的文本放入同一个框中,只需使用更长的文本:-)

看这里:

mytext="Dear Kids\! One day you'll learn everything about Santa Claus. On that day, please also remember what they told you about Jesus."

convert                            \
  -background '#0008'              \
  -gravity center                  \
  -fill white                      \
  -size 260x70 caption:"${mytext}" \
   funny-santa.jpg                 \
  +swap                            \
  -gravity south                   \
  -composite                       \
   funny-santa---2.jpg 
Run Code Online (Sandbox Code Playgroud)