Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

image processing - why font list is empty for imagemagick?

I am trying to use ImageMagick to add some text to an image. But I found it always said that my specified font doesn't exist. After reading the manual carefully I noticed that I can use convert -list font to output all the available fonts, but after trying I figured out that the list of available font is empty.

This is what I get:

shell$ convert -list font
shell$ 

Thanks for any kind of tips.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just managed to tell ImageMagick about the fonts on my OSX system like this:

# 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 -L 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>

How to find the correct folder for your type.xml file

The folder where type.xml is stored can vary enormously between systems and versions. Most recently the user configuration folder seems to be ~/.config/ImageMagick, but the best way I know of finding it is to run the following command to see where ImageMagick is looking:

convert -debug configure -list font 2>&1 | grep -E "Searching|Loading"

Searching for configure file: "/usr/local/Cellar/imagemagick/7.0.11-6/share/ImageMagick-7/type.xml"
Searching for configure file: "/usr/local/Cellar/imagemagick/7.0.11-6/lib/ImageMagick//config-Q16HDRI/type.xml"
Searching for configure file: "/usr/local/Cellar/imagemagick/7.0.11-6/etc/ImageMagick-7/type.xml"
Searching for configure file: "/usr/local/Cellar/imagemagick/7.0.11-6/share/doc/ImageMagick-7/type.xml"
Searching for configure file: "/Users/username/.config/ImageMagick/type.xml"
Loading type configure file "/usr/local/Cellar/imagemagick/7.0.11-6/etc/ImageMagick-7/type.xml" ...
Loading type configure file "/usr/local/Cellar/imagemagick/7.0.11-6/etc/ImageMagick-7/type-ghostscript.xml" ...
Loading type configure file "/Users/username/.config/ImageMagick/type.xml" ...

So there are lots of places you could insert the fonts. In general, if you choose a folder starting with /etc or /usr/local the fonts will be available for all users and for scripts in your web server to use - if you want that. On the other hand, if you are just a single user, you may prefer to keep the font config file in your login directory, e.g. ~/.config/ImageMagick/type.xml.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...