我怎样才能找出最适合 imagemagick 使用的字体大小
how can I find out font size used by best fit in imagemagick
这个问题与 http://www.imagemagick.org/Usage/text/#caption_bestfit .
有关
假设我在 40x40 区域使用字体 "Comic-Sans-MS-Bold" 写一个数字,这样它就可以占用最大 space 并且不会溢出。
假设 imagemagick 选择字体大小 'x' .
如果我要在 40x40 区域使用 "Comic-Sans-MS-Bold" 字体写一个两位数。
然后 imagemagick 会选择其他字体大小 'y' .
是否有调试选项或其他方法,我可以使用它找出在指定区域写入特定文本的字体大小。
实际上,我需要那个字体大小,这样当我使用在 canvas 上绘制文本创建类似图像时,我可以在我的 tkinter 脚本中明确指定它。
谢谢
顺便说一句,imagemagick 论坛被锁定了。
您可以在 ImageMagick 标题中找到字体大小:使用 -debug annotate 如下。你会得到一个长长的列表,显示所有尝试过的字体大小迭代。最后一个就是你想要的。
convert -debug annotate -size 200x50 -background white -font candice caption:"This Is Some Text" result.jpg
2020-06-01T19:02:46+00:00 0:00.044 0.040u 6.9.11 Annotate convert[53791]: annotate.c/RenderFreetype/1486/Annotate
Font /Library/Fonts/Candice.ttf; font-encoding none; text-encoding none; pointsize 12
2020-06-01T19:02:46+00:00 0:00.045 0.040u 6.9.11 Annotate convert[53791]: annotate.c/GetTypeMetrics/862/Annotate
Metrics: text: T; width: 12.5312; height: 15; ascent: 10; descent: -4; max advance: 15; bounds: 0.484375,-1 12.5312,9; origin: 12.5312,0; pixels per em: 12,12; underline position: -1.26; underline thickness: 0.6
2020-06-01T19:02:46+00:00 0:00.045 0.040u 6.9.11 Annotate convert[53791]: annotate.c/RenderFreetype/1486/Annotate
Font /Library/Fonts/Candice.ttf; font-encoding none; text-encoding none; pointsize 12
2020-06-01T19:02:46+00:00 0:00.046 0.040u 6.9.11 Annotate convert[53791]: annotate.c/GetTypeMetrics/862/Annotate
Metrics: text: Th; width: 16.3438; height: 15; ascent: 10; descent: -4; max advance: 15; bounds: 0.125,-0.328125 6.34375,8; origin: 16.3438,0; pixels per em: 12,12; underline position: -1.26; underline thickness: 0.6
2020-06-01T19:02:46+00:00 0:00.046 0.040u 6.9.11 Annotate convert[53791]: annotate.c/RenderFreetype/1486/Annotate
Font /Library/Fonts/Candice.ttf; font-encoding none; text-encoding none; pointsize 12
2020-06-01T19:02:46+00:00 0:00.046 0.040u 6.9.11 Annotate convert[53791]: annotate.c/GetTypeMetrics/862/Annotate
.
.
.
Metrics: text: This Is Some Text; width: 193.703; height: 28; ascent: 19; descent: -7; max advance: 29; bounds: 0.734375,-2.09375 7.70312,11.8906; origin: 193.703,0; pixels per em: 23,23; underline position: -2.415; underline thickness: 1.15
2020-06-01T19:02:46+00:00 0:00.194 0.180u 6.9.11 Annotate convert[53791]: annotate.c/RenderFreetype/1486/Annotate
Font /Library/Fonts/Candice.ttf; font-encoding none; text-encoding none; pointsize 23
所以结果是pointsize 23
这是在 ImageMagick 中执行此操作的更好方法。
convert -size 200x50 -background white -font candice caption:"This Is Some Text" -format "%[caption:pointsize]\n" info:
23
这个问题与 http://www.imagemagick.org/Usage/text/#caption_bestfit .
有关
假设我在 40x40 区域使用字体 "Comic-Sans-MS-Bold" 写一个数字,这样它就可以占用最大 space 并且不会溢出。
假设 imagemagick 选择字体大小 'x' .
如果我要在 40x40 区域使用 "Comic-Sans-MS-Bold" 字体写一个两位数。
然后 imagemagick 会选择其他字体大小 'y' .
是否有调试选项或其他方法,我可以使用它找出在指定区域写入特定文本的字体大小。
实际上,我需要那个字体大小,这样当我使用在 canvas 上绘制文本创建类似图像时,我可以在我的 tkinter 脚本中明确指定它。
谢谢
顺便说一句,imagemagick 论坛被锁定了。
您可以在 ImageMagick 标题中找到字体大小:使用 -debug annotate 如下。你会得到一个长长的列表,显示所有尝试过的字体大小迭代。最后一个就是你想要的。
convert -debug annotate -size 200x50 -background white -font candice caption:"This Is Some Text" result.jpg
2020-06-01T19:02:46+00:00 0:00.044 0.040u 6.9.11 Annotate convert[53791]: annotate.c/RenderFreetype/1486/Annotate
Font /Library/Fonts/Candice.ttf; font-encoding none; text-encoding none; pointsize 12
2020-06-01T19:02:46+00:00 0:00.045 0.040u 6.9.11 Annotate convert[53791]: annotate.c/GetTypeMetrics/862/Annotate
Metrics: text: T; width: 12.5312; height: 15; ascent: 10; descent: -4; max advance: 15; bounds: 0.484375,-1 12.5312,9; origin: 12.5312,0; pixels per em: 12,12; underline position: -1.26; underline thickness: 0.6
2020-06-01T19:02:46+00:00 0:00.045 0.040u 6.9.11 Annotate convert[53791]: annotate.c/RenderFreetype/1486/Annotate
Font /Library/Fonts/Candice.ttf; font-encoding none; text-encoding none; pointsize 12
2020-06-01T19:02:46+00:00 0:00.046 0.040u 6.9.11 Annotate convert[53791]: annotate.c/GetTypeMetrics/862/Annotate
Metrics: text: Th; width: 16.3438; height: 15; ascent: 10; descent: -4; max advance: 15; bounds: 0.125,-0.328125 6.34375,8; origin: 16.3438,0; pixels per em: 12,12; underline position: -1.26; underline thickness: 0.6
2020-06-01T19:02:46+00:00 0:00.046 0.040u 6.9.11 Annotate convert[53791]: annotate.c/RenderFreetype/1486/Annotate
Font /Library/Fonts/Candice.ttf; font-encoding none; text-encoding none; pointsize 12
2020-06-01T19:02:46+00:00 0:00.046 0.040u 6.9.11 Annotate convert[53791]: annotate.c/GetTypeMetrics/862/Annotate
.
.
.
Metrics: text: This Is Some Text; width: 193.703; height: 28; ascent: 19; descent: -7; max advance: 29; bounds: 0.734375,-2.09375 7.70312,11.8906; origin: 193.703,0; pixels per em: 23,23; underline position: -2.415; underline thickness: 1.15
2020-06-01T19:02:46+00:00 0:00.194 0.180u 6.9.11 Annotate convert[53791]: annotate.c/RenderFreetype/1486/Annotate
Font /Library/Fonts/Candice.ttf; font-encoding none; text-encoding none; pointsize 23
所以结果是pointsize 23
这是在 ImageMagick 中执行此操作的更好方法。
convert -size 200x50 -background white -font candice caption:"This Is Some Text" -format "%[caption:pointsize]\n" info:
23