你可以设置一个大小,指定文本可用的空间有多大,
ImageMagick 将选择最大的点大小文本来适应它:
magick -gravity center -background black -fill white -size 400x300 -font /System/Library/Fonts/MarkerFelt.ttc caption:"Short Text" short.png
![enter image description here](https://istack.dev59.com/09yHU.webp)
magick -gravity center -background black -fill white -size 400x300 -font /System/Library/Fonts/MarkerFelt.ttc caption:"Somewhat longer text that will get rendered in a smaller font" long.png
![enter image description here](https://istack.dev59.com/F3gn2.webp)
如果您想要文字周围有边距,您可以设置文本的最大尺寸,然后使用
-extent
增加画布的大小 - 我将以红色执行此操作,以便您可以看到
-extent
添加了什么:
magick -gravity center -background black -fill white -size 400x300 -font /System/Library/Fonts/MarkerFelt.ttc caption:"Somewhat longer text" -background red -extent 410x400 long.png
![enter image description here](https://istack.dev59.com/nEqS5.webp)
如果您正在从文件中读取行来生成成千上万的图像,则可以通过以下方式从另一个命令中输入文本:
echo -n "Text supplied by other command" | magick -gravity center -background black -fill white -size 400x300 -font /System/Library/Fonts/MarkerFelt.ttc caption:@- result.png
![enter image description here](https://istack.dev59.com/G7f6m.webp)
如果您想知道ImageMagick选择了什么点大小,您可以按照以下方式获取:
magick identify -format "%[caption:pointsize]\n" result.png
59