在安装了自制程序的 mac 上用 Image::Magick 注释图像

Annotating images with Image::Magick on mac installed with homebrew

我在我的 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 的部分输出

  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