perl - 在使用自制软件安装的 Mac 上使用 Image::Magick 注释图像
问题描述
我在我的 Mac 上安装了带有自制软件的 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');
我想它找不到字体,但也许还有其他问题。没有错误被抛出。我已经用自制软件安装了 ghostscript,但这没有帮助。
identify -list 字体的部分输出
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查找文本输出时遇到问题,请尝试以下建议:
建议一
使用对比填充和描边,这样您就可以合理地确定在任何背景上看到您的文本:
magick ... -fill cyan -stroke magenta ...
建议二
将重力设置为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
推荐阅读
- ios - 滑动手势iOS swift
- ruby-on-rails - Rails - 检测字符串中完全匹配的关键字
- python - 如何使用 discord.py 在系统消息频道中发送问候消息
- java - 数字向量的 JSON 格式
- python - 如何将下一行作为不和谐机器人的输入
- python - Python AWS Lambda 函数 ""errorMessage": "'function' 对象没有属性 'loads'"
- c - 有人可以解释 C 使用 #define UMAX (a, b) ((a) > (b) ? (a) : (b)) 指令的硬逻辑错误,该指令返回较低的值,在 2 个编译器中
- nginx - 如何将通配符传递给 nginx 代理主机头?
- python - python在进入下一行时播放声音/歌曲
- python - 如何确定日期时间列中的值是否在来自另一个数据帧的任何一对日期时间之间