5

我正在将 ImageMagick 命令集成到用 Node.js 编写的 Firebase 函数中。我已经安装了 Ghostscript 并且有完整的可用字体列表:

convert -list font

Path: /usr/local/Cellar/imagemagick/7.0.8-10/etc/ImageMagick-7/type-apple.xml
  Font: AndaleMono
    family: Andale Mono
    style: Undefined
    stretch: Undefined
    weight: 0
    glyphs: /Library/Fonts//Andale Mono.ttf
  Font: AppleChancery
    family: Apple Chancery
    style: Undefined
    stretch: Undefined
    weight: 0
    glyphs: /Library/Fonts//Apple Chancery.ttf
  Font: AppleMyungjo
    family: AppleMyungjo
    style: Undefined
    stretch: Undefined
    weight: 0
    glyphs: /Library/Fonts//AppleMyungjo.ttf

这是我的代码:

exec(`convert ${tempFilePath} -font /Users/emma/Library/Fonts/Nunito-Regular.ttf -fill white -pointsize 60 -gravity center -draw "text 0,300 'this is a label'" ${tempFilePath}`, {stdio: 'ignore'}, (err, stdout) => {
         if (err) {
             console.error('Failed to label image.', err);
             reject(err);
         } else {
             resolve(stdout);
         }
});

我也试过:

exec(`convert ${tempFilePath} -font Arial -fill white -pointsize 60 -gravity center -draw "text 0,300 'this is a label'" ${tempFilePath}`, {stdio: 'ignore'}, (err, stdout) => {
       if (err) {
          console.error('Failed to label image.', err);
          reject(err);
       } else {
          resolve(stdout);
       }
});

我得到的错误是:

convert: unable to read font `/Library/Fonts//Andale' @ warning/annotate.c/RenderType/872
4

1 回答 1

1

根据@fmw42建议:

在一些使用 Imagemagick 的工具上,它们不使用系统 ENV 变量。

因此,我看到了诸如 PHP Imagick 无法找到 Ghostscript 的情况。

在这些情况下,解决方案是将 Ghostscript 的完整路径放在它gsdelegates.xmlImagemagick 文件中使用的那些行中,例如 PS、EPS 列表gs

请参阅https://imagemagick.org/script/resources.phpdelegates.xml 及其可能的位置。我的在 /usr/local/etc/ImageMagick-6/delegates.xml

所以可能的解决方案是安装gs工具。

在 MacOS 上:brew install gs.

相关帖子:https ://imagemagick.org/discourse-server/viewtopic.php?t=34911 。

于 2020-07-14T15:36:18.373 回答