ImageMagick:为什么这个文字不会扩展填充?

时间:2018-02-05 00:01:51

标签: image imagemagick imagemagick-convert

我正在阅读label的{​​{3}},如果我指定-size它似乎应该神奇地尽可能地填充空间。

我想这样做,所以这个文字尽可能大。我会在标题中设置\n个字符(如果绝对必要的话)。

我宁愿\n自动计算,但似乎label是最大可能的(但不支持自动\n),而{{1}将在适当的位置添加caption(但不支持填充空间的动态大小)。

我的目标是基本上获得最大可能的文本,无论是1行还是3行,以适应绿色框(在2条红色\n行之间)。

下面是两个不会改变的例子。绿色只是暂时的,所以我可以调试。

这是我的代码文章(没有其余部分):

******

多...

-size 290x54 -background green -fill blue -font ArialB -gravity center label:'Join Us'

我不知道这是否可能,但理想情况下它应该问“标题是否在1行,它的最大大小是多少?如果我在单词1之后加-size 290x54 -background green -fill blue -font ArialB -gravity center label:'Join Us Tomorrow\nFor An HVAC Meeting' ,那么它可能是最大尺寸吗?如果我在第2个字之后加上\n,它的最大尺寸是多少?“......然后选择其中最大尺寸。

text handling docs

enter image description here

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:1)

在ImageMagick中,通过指定widthxheight但不指定pointsize来使用标题。 ImageMagick会找出合适的点数来填充文本框。例如:

convert -size 500x200 -background white -font arial -fill black -gravity center caption:"Testing" -bordercolor red -border 1 test1.png

enter image description here

convert -size 500x200 -background white -font arial -fill black -gravity center caption:"Should Be Bigger" -bordercolor red -border 1 test2.png

enter image description here

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

enter image description here

你也可以包括分数,只要你的文字对于盒子的区域来说不是太长。

convert -size 500x200 -background white -font arial -fill black -pointsize 48 -gravity center caption:"Testing" -bordercolor red -border 1 test1b.png

enter image description here

convert -size 500x200 -background white -font arial -fill black -pointsize 48 -gravity center caption:"Should Be Bigger" -bordercolor red -border 1 test2b.png

enter image description here

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

enter image description here

但是,如果你选择的字体太大,你会得到这个:

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

enter image description here

答案 1 :(得分:1)

你的命令对我来说只有一次修正。显然,即使我添加了-respect-parenthesis,pointize也会从你的主命令泄漏到括号处理中。所以解决方案是在括号命令中添加+ 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文件放在可以在与发出命令的位置相同的级别访问它。您可以更改它的路径。

enter image description here

相关问题