Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 705
AGamePlayer Avatar asked Jul 11 '14 11:07

AGamePlayer


1 Answers

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.

like image 126
Mark Setchell Avatar answered Oct 01 '22 02:10

Mark Setchell