ImageMagick转换命令无法读取字体

7

我正在将一个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}里面是什么? - Mark Setchell
如果您的图片高度小于600像素,请尝试将“300”更改为“0”。 - Mark Setchell
你说你使用了 Nunito-Regular 或者 Arial 字体,但错误信息却提到了 Andale - 你确定你提供的是匹配的代码和错误信息吗?我猜测你的字体文件名中有空格,请尝试用双引号将其括起来。 - Mark Setchell
1
在一些使用Imagemagick的工具中,它们不使用系统ENV变量。因此我看到过像PHP Imagick这样的情况,它无法找到Ghostscript。在这些情况下,解决方案是在Imagemagick的delegates.xml文件中将gs用于类似PS、EPS这样列出gs的行的完整路径放置到Ghostscript。我对Firebase或Node一无所知,但这是值得研究的。请参阅 https://www.imagemagick.org/script/resources.php 获取delegates.xml及其可能的位置。我的路径为/usr/local/etc/ImageMagick-6/delegates.xml。 - fmw42
@fmw42 - 对我来说有效。gs找不到,可能与软件更新有关。在MacOS上执行“brew install gs”并解决了问题。 - cwingrav
显示剩余4条评论
1个回答

1
根据@fmw42的建议:
在一些使用Imagemagick的工具中,它们不使用系统环境变量。因此,我曾经看到过一些情况,例如PHP Imagick无法找到Ghostscript。
在这些情况下,解决方法是在Imagemagick的delegates.xml文件中将用于PS、EPS等列出gs的行中使用gs的完整路径。
请参见https://imagemagick.org/script/resources.php查看delegates.xml及其可能的位置。我使用的位置为/usr/local/etc/ImageMagick-6/delegates.xml 因此,可能的解决方法是安装gs工具。
在MacOS上: brew install gs.

相关文章:https://imagemagick.org/discourse-server/viewtopic.php?t=34911


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接