ImageMagick:为什么这个文本不会扩展来填充?
ImageMagick: Why won't this text expand to fill?
我正在为 label
阅读 text handling docs,似乎如果我指定 -size
它应该神奇地变得尽可能大以填充 space。
我想让这段文字尽可能大。我会在标题中自己设置 \n
个字符(如果绝对必要)。
我宁愿 \n
自动计算,但似乎 label
是最大可能的(但不支持自动 \n
),而 caption
将在适当的地方添加 \n
(但不支持填充以适应 space 的动态大小)。
我的目标是基本上获得尽可能大的文本,无论是 1 行还是 3 行,以适应绿色框(2 红色 ******
行之间)。
下面是 2 个例子,说明它不会改变。绿色只是暂时的,所以我可以调试。
这是我对这篇文章的代码(没有其余部分):
-size 290x54 -background green -fill blue -font ArialB -gravity center label:'Join Us'
多行...
-size 290x54 -background green -fill blue -font ArialB -gravity center label:'Join Us Tomorrow\nFor An HVAC Meeting'
我不知道这是否可能,但理想情况下它应该询问 "if the title is on 1 line, what is the max size it could be? if I put a \n
after word 1, what is the max size it could be? if i put a \n
after word 2, what is the max size it could be?"... 然后选择其中最大的一个。
在 ImageMagick 中,通过指定 widthxheight 而不是点大小来使用标题。 ImageMagick 将计算出合适的点大小来将文本填充到框中。例如:
convert -size 500x200 -background white -font arial -fill black -gravity center caption:"Testing" -bordercolor red -border 1 test1.png
convert -size 500x200 -background white -font arial -fill black -gravity center caption:"Should Be Bigger" -bordercolor red -border 1 test2.png
convert -size 500x200 -background white -font arial -fill black -gravity center caption:"This is a title that will be fairly long and I want it to fit nicely" -bordercolor red -border 1 test3.png
您也可以包括磅值,只要您的文本对于框的区域而言不会太长。
convert -size 500x200 -background white -font arial -fill black -pointsize 48 -gravity center caption:"Testing" -bordercolor red -border 1 test1b.png
convert -size 500x200 -background white -font arial -fill black -pointsize 48 -gravity center caption:"Should Be Bigger" -bordercolor red -border 1 test2b.png
convert -size 500x200 -background white -font arial -fill black -pointsize 48 -gravity center caption:"This is a title that will be fairly long and I want it to fit nicely" -bordercolor red -border 1 test3b.png
但是,如果你选择的字体太大,你会得到这个:
convert -size 500x200 -background white -font arial -fill black -pointsize 64 -gravity center caption:"This is a title that will be fairly long and I want it to fit nicely" -bordercolor red -border 1 test3c.png
你的命令对我来说只要修正一下就可以了。显然,即使我添加了 -respect-parenthesis,pointsize 从您的主命令泄漏到括号处理中。所以解决方案是在括号命令中添加+pointsize。这是我的命令和结果。
magick -respect-parenthesis -size 298x248 canvas:white \( 'arrows.png' -resize 300x \) -gravity northwest -geometry +0+140 -compose over -composite -bordercolor '#cccccc' -border 1 -font Arial -fill red -pointsize 22 -gravity north -annotate +0+4 '*************************' -font Arial -fill red -pointsize 22 -gravity north -annotate +0+68 '*************************' -font Arial -fill green -pointsize 15 -gravity south -annotate +0+64 'hvac.com' \( -size 279x55 +pointsize -background green -fill blue -font ArialB -gravity center caption:'test headline' \) -gravity center -geometry +0-82 -compose over -composite output.png
请注意,我将 arrows.png 文件放在可以访问它的位置,与发出命令的位置处于同一级别。您可以更改它的路径。
我正在为 label
阅读 text handling docs,似乎如果我指定 -size
它应该神奇地变得尽可能大以填充 space。
我想让这段文字尽可能大。我会在标题中自己设置 \n
个字符(如果绝对必要)。
我宁愿 \n
自动计算,但似乎 label
是最大可能的(但不支持自动 \n
),而 caption
将在适当的地方添加 \n
(但不支持填充以适应 space 的动态大小)。
我的目标是基本上获得尽可能大的文本,无论是 1 行还是 3 行,以适应绿色框(2 红色 ******
行之间)。
下面是 2 个例子,说明它不会改变。绿色只是暂时的,所以我可以调试。
这是我对这篇文章的代码(没有其余部分):
-size 290x54 -background green -fill blue -font ArialB -gravity center label:'Join Us'
多行...
-size 290x54 -background green -fill blue -font ArialB -gravity center label:'Join Us Tomorrow\nFor An HVAC Meeting'
我不知道这是否可能,但理想情况下它应该询问 "if the title is on 1 line, what is the max size it could be? if I put a \n
after word 1, what is the max size it could be? if i put a \n
after word 2, what is the max size it could be?"... 然后选择其中最大的一个。
在 ImageMagick 中,通过指定 widthxheight 而不是点大小来使用标题。 ImageMagick 将计算出合适的点大小来将文本填充到框中。例如:
convert -size 500x200 -background white -font arial -fill black -gravity center caption:"Testing" -bordercolor red -border 1 test1.png
convert -size 500x200 -background white -font arial -fill black -gravity center caption:"Should Be Bigger" -bordercolor red -border 1 test2.png
convert -size 500x200 -background white -font arial -fill black -gravity center caption:"This is a title that will be fairly long and I want it to fit nicely" -bordercolor red -border 1 test3.png
您也可以包括磅值,只要您的文本对于框的区域而言不会太长。
convert -size 500x200 -background white -font arial -fill black -pointsize 48 -gravity center caption:"Testing" -bordercolor red -border 1 test1b.png
convert -size 500x200 -background white -font arial -fill black -pointsize 48 -gravity center caption:"Should Be Bigger" -bordercolor red -border 1 test2b.png
convert -size 500x200 -background white -font arial -fill black -pointsize 48 -gravity center caption:"This is a title that will be fairly long and I want it to fit nicely" -bordercolor red -border 1 test3b.png
但是,如果你选择的字体太大,你会得到这个:
convert -size 500x200 -background white -font arial -fill black -pointsize 64 -gravity center caption:"This is a title that will be fairly long and I want it to fit nicely" -bordercolor red -border 1 test3c.png
你的命令对我来说只要修正一下就可以了。显然,即使我添加了 -respect-parenthesis,pointsize 从您的主命令泄漏到括号处理中。所以解决方案是在括号命令中添加+pointsize。这是我的命令和结果。
magick -respect-parenthesis -size 298x248 canvas:white \( 'arrows.png' -resize 300x \) -gravity northwest -geometry +0+140 -compose over -composite -bordercolor '#cccccc' -border 1 -font Arial -fill red -pointsize 22 -gravity north -annotate +0+4 '*************************' -font Arial -fill red -pointsize 22 -gravity north -annotate +0+68 '*************************' -font Arial -fill green -pointsize 15 -gravity south -annotate +0+64 'hvac.com' \( -size 279x55 +pointsize -background green -fill blue -font ArialB -gravity center caption:'test headline' \) -gravity center -geometry +0-82 -compose over -composite output.png
请注意,我将 arrows.png 文件放在可以访问它的位置,与发出命令的位置处于同一级别。您可以更改它的路径。