[英]Annotating images with Image::Magick on mac installed with homebrew
我已经在Mac上安装了Homebrew的ImageMagick软件,并且正在使用Image :: Magick Perl模块。 我试图弄清楚如何用一些文本注释图像。 我没有尝试过的工作:
$error = $image->Annotate(font => 'Courier', gravity => 'North', pointsize=>100, fill=>'black', text => 'blah blah');
$error = $image->Annotate(font => '/Library/Fonts/Impact.ttf', gravity => 'North', pointsize=>100, fill=>'black', text => 'blah blah');
我发现它找不到字体,但也许其他地方有问题。 没有引发任何错误。 我已经用Homebrew安装了ghostscript,但这没有帮助。
标识列表字体的部分输出
Font: Times-BoldItalic
family: Times
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/n021024l.pfb
Font: Times-Italic
family: Times
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n021023l.pfb
Font: Times-Roman
family: Times
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n021003l.pfb
通常,如果您在使用ImageMagick查找文本输出时遇到问题,请尝试以下建议:
建议1
使用对比填充和笔触,这样您就可以确定在任何背景上都能看到文字:
magick ... -fill cyan -stroke magenta ...
建议2
将重力设置为center
,以防书写超出图像边缘:
magick ... -gravity center ...
建议3
指定字体文件的完整路径 ,以便即使未在其配置文件中配置ImageMagick也会找到它:
magick ... -font /Library/Fonts/Impact.ttf ...
建议4
加载后重新分页图像,因此它忘记了以前可能是较大图像的一部分并被裁剪时可能具有的所有旧页面设置:
magick ... +repage ...
因此,总而言之,请尝试以下命令:
magick -size 100x100 xc:white -gravity center -fill cyan -stroke magenta -font /Library/Fonts/Impact.ttf -annotate 0 "Hi there" result.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.