Fonts ImageMagick convert命令无法读取字体
我正在将ImageMagick命令集成到Node.js中编写的Firebase函数中。我已经安装了Ghostscript,并且有一个完整的可用字体列表:Fonts ImageMagick convert命令无法读取字体,fonts,imagemagick,imagemagick-convert,node-imagemagick,Fonts,Imagemagick,Imagemagick Convert,Node Imagemagick,我正在将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
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
根据建议:
在一些使用Imagemagick的工具上,它们不使用系统 环境变量 因此,我看到过PHP Imagick无法定位的情况 鬼脚本 在这些情况下,解决方案是将完整路径放入Ghostscript 其中,它使用Imagemagick的
delegates.xml
文件中的gs
,用于
那些列有gs
的行,如PS、EPS
有关delegates.xml的信息,请参见
以及它可能的位置。我的在
/usr/local/etc/ImageMagick-6/delegates.xml
因此,可能的解决方案是安装gs
工具
在MacOS上:brew安装gs
相关帖子:.在${tempFilePath}
中有什么?如果您的图片高度小于600像素,请尝试将300
更改为0
。@MarkSetchell${tempFilePath}正是我正在转换的图像的路径。我之前在代码中把它下载到了一个临时目录中。你说你使用了Nunito-Regular
或Arial
,但错误消息是关于Andale
-你真的给出了匹配的代码和错误消息吗?我猜字体文件的名称中有空格,请尝试用双引号将其括起来。在某些使用Imagemagick的工具上,它们不使用system ENV变量。因此,我看到过一些情况,比如PHP Imagick,它无法定位Ghostscript。在这些情况下,解决方案是将Ghostscript的完整路径放在Imagemagick的delegates.xml文件中,用于列出gs
的PS、EPS等行。我对Firebase或Node一无所知,但这是需要研究的。有关delegates.xml及其可能的位置,请参见。我的地址是/usr/local/etc/ImageMagick-6/delegates.xml