首页 > 解决方案 > 在使用自制软件安装的 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

标签: perlimagemagick

解决方案


一般来说,如果您在使用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

在此处输入图像描述


推荐阅读