我正在将一个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 SetchellNunito-Regular
或者Arial
字体,但错误信息却提到了Andale
- 你确定你提供的是匹配的代码和错误信息吗?我猜测你的字体文件名中有空格,请尝试用双引号将其括起来。 - Mark Setchellgs
用于类似PS、EPS这样列出gs
的行的完整路径放置到Ghostscript。我对Firebase或Node一无所知,但这是值得研究的。请参阅 https://www.imagemagick.org/script/resources.php 获取delegates.xml及其可能的位置。我的路径为/usr/local/etc/ImageMagick-6/delegates.xml。 - fmw42