【发布时间】: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-Regular或Arial,但错误信息是关于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