【问题标题】:ImageMagick convert command Unable to Read FontImageMagick 转换命令无法读取字体
【发布时间】:2019-01-23 14:46:55
【问题描述】:

我正在将 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

【问题讨论】:

  • ${tempFilePath} 中有什么内容?
  • 尝试将 300 更改为 0,以防您的图片高度小于 600 像素。
  • @MarkSetchell ${tempFilePath} 只是我正在转换的图像的路径。我之前在代码中将它下载到了一个临时目录。
  • 您说您使用了Nunito-RegularArial,但错误信息是关于Andale - 您真的给出了匹配的代码和错误信息吗?我猜您的字体文件的名称中有空格,请尝试用双引号将其括起来。
  • 在一些使用 Imagemagick 的工具上,它们不使用系统 ENV 变量。因此,我看到了诸如 PHP Imagick 无法找到 Ghostscript 的情况。在这些情况下,解决方案是将使用gs 的Ghostscript 的完整路径放在Imagemagick 的delegates.xml 文件中,用于那些列出gs 的行,例如PS、EPS。我对 Firebase 或 Node 一无所知,但这是值得研究的。有关 delegates.xml 及其可能的位置,请参见 imagemagick.org/script/resources.php。我的在 /usr/local/etc/ImageMagick-6/delegates.xml

标签: fonts imagemagick imagemagick-convert node-imagemagick


【解决方案1】:

根据@fmw42 建议:

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

所以我看到了无法定位的情况,例如 PHP Imagick Ghostscript。

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

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.

【讨论】:

    猜你喜欢
    • 2012-12-05
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 2017-04-05
    • 2019-12-20
    • 2017-06-20
    • 2017-12-21
    相关资源
    最近更新 更多