我正在尝试使用ImageMagick向图像添加一些文本。但我发现它总是说我指定的字体不存在。仔细阅读本手册后,我注意到我可以使用convert -list font
输出所有可用字体,但在尝试后我发现可用字体列表为空。
这就是我得到的:
shell$ convert -list font
shell$
感谢您提供任何建议。
答案 0 :(得分:43)
我设法告诉 ImageMagick 关于我的OSX系统上的字体,如下所示:
# Make a new directory for ImageMagick local settings and cd into it
mkdir ~/.magick
cd ~/.magick
# Grab script to find all fonts on system and store them in a config file
curl http://www.imagemagick.org/Usage/scripts/imagick_type_gen > type_gen
# Run script, telling it where my fonts are and create "type.xml" file with list
find /System/Library/Fonts /Library/Fonts ~/Library/Fonts -name "*.[to]tf" | perl type_gen -f - > type.xml
# Go to ImageMagick config folder - see note at end to find correct folder
cd /usr/local/Cellar/imagemagick/6.8.9-1/etc/ImageMagick-6
# Edit system config file called "type.xml" and add line near end to tell IM to look at local file we made in earlier step
<typemap>
<include file="type-ghostscript.xml" />
<include file="~/.magick/type.xml" /> ### THIS LINE ADDED ###
</typemap>
type.xml
文件找到正确的文件夹存储type.xml
的文件夹在系统和版本之间会有很大差异。我知道找到它的最好方法是运行以下命令来查看 ImageMagick 正在寻找的位置:
convert -debug configure -list font 2>&1 | grep -E "Searching|Loading"
Searching for configure file: "/usr/local/Cellar/imagemagick/6.9.5-0/share/ImageMagick-6/type.xml"
Searching for configure file: "/usr/local/Cellar/imagemagick/6.9.5-0/lib/ImageMagick//config-Q16/type.xml"
Searching for configure file: "/usr/local/Cellar/imagemagick/6.9.5-0/etc/ImageMagick-6/type.xml"
Searching for configure file: "/usr/local/Cellar/imagemagick/6.9.5-0/share/doc/ImageMagick-6/type.xml"
Searching for configure file: "/Users/mark/.config/ImageMagick/type.xml"
Searching for configure file: "/Users/mark/.magick/type.xml"
Loading type configure file "/usr/local/Cellar/imagemagick/6.9.5-0/etc/ImageMagick-6/type.xml" ...
Loading type configure file "/usr/local/Cellar/imagemagick/6.9.5-0/etc/ImageMagick-6/type-apple.xml" ...
Loading type configure file "/usr/local/Cellar/imagemagick/6.9.5-0/etc/ImageMagick-6/type-ghostscript.xml" ...
Loading type configure file "/Users/mark/.magick/type.xml" ...
因此,有很多地方可以插入字体。通常,如果您选择以/etc
或/usr/local
开头的文件夹,则所有用户和Web服务器中的脚本都可以使用这些字体 - 如果您愿意的话。另一方面,如果您只是一个用户,您可能更喜欢将字体配置文件保留在登录目录中,例如$HOME/.magick/type.xml
。
答案 1 :(得分:4)
使用MacOs Catalina上的ImageMagic 7.0.10,我完成了以下工作,达到了目的。
/usr/local/Cellar/imagemagick/7.0.10-7/etc/ImageMagick-7/type.xml
并将type-ghostscript
替换为type-apple
/usr/local/Cellar/imagemagick/7.0.10-7/etc/ImageMagick-7/type-apple.xml
,并在所有字形路径的前面添加“ / System / Library / Fonts / Supplemental”