31

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.

AGamePlayer
  • 7,404
  • 19
  • 62
  • 119

2 Answers2

63

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.

Saaru Lindestøkke
  • 2,067
  • 1
  • 25
  • 51
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • 1
    Thanks. I got stuck at this `# Go to ImageMagick config folder`. I don't have a `/usr/local/Cellar/` in my harddrive. – AGamePlayer Jul 12 '14 at 08:47
  • 1
    I finally managed to locate the `etc` folder in the package folder. But after running the `convert` command, I got this: `convert: delegate library support not built-in '/Library/Fonts/Microsoft/Arial.ttf' (Freetype) @ warning/annotate.c/RenderFreetype/1535.` Just fyi, I now can see things after running `convert -list font` – AGamePlayer Jul 12 '14 at 09:09
  • Mmmmm... if you don't have a /usr/local/Cellar, then I suspect you are not using the `homebrew` package manager that I use. I have never succeeded in making ImageMagick work without using that and I use it for installing everything from `sed`, through `date` through `awk`, `lynx`, `netcat`, `wget`, `jhead`, `parallel`, `redis`. I am not sure I can help much further if you don't use homebrew. Maybe hunt around your Mac for a `type.xml` file, save it, and replace it with the one we created in my answer and see if that helps. Sorry, I don't know much more. – Mark Setchell Jul 12 '14 at 09:29
  • Thanks. I have already found an post here http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=21070 but unluckily even if I generated a `type.xml` file it still doesn't work. The XML file looks like this: `` Is it correct? And in the post people are talking about using `convert -list configure` but when I run it I got this: `convert: unable to access configure file 'configure.xml' @ warning/configure.c/GetConfigureOptions/706`. – AGamePlayer Jul 12 '14 at 09:43
  • another question, what is `type-ghostscript.xml` for? thanks! – AGamePlayer Jul 12 '14 at 10:01
  • Thanks, it works! You are looking for .ttf only though and imagemagick supports .otf too (for Chinese,Japanese and Korean). The command should be: find /System/Library/Fonts /Library/Fonts ~/Library/Fonts -name "*.ttf" -or -name "*.otf" | perl type_gen -f - > type.xml – k3a Dec 08 '14 at 00:42
  • @kexik Thank you for your feedback, I will change my post to incorporate ".otf" fonts too. – Mark Setchell Dec 08 '14 at 09:05
  • 6
    Thanks! I created my `type.xml` in `~/.config/ImageMagick` and it was detected automatically! – fnurl Jul 13 '16 at 08:52
  • If you install imagemagick with homebrew, use: `brew install imagemagick --with-little-cms`. After this the instructions worked perfectly. Thanks! – QuesterZen Jul 31 '17 at 13:46
  • 2
    I installed my image magick magic with homebrew, and it had all of the system fonts. However, `convert -list fonts` showed that it only looked in /etc/Image-Magick.../type-apple.xml and not in type.xml (where we add the created file to the typemap). I had to manually copy and paste the new type.xml into type-apple.xml to get it to work. Super smelly. – jessi Aug 24 '18 at 20:04
  • Thanks for the clear instructions, this worked great for me. – SkippyFlipjack Oct 26 '18 at 16:55
  • 4
    Works great, but I had to set the absolute path Not Working ### THIS LINE ADDED ### Working ### THIS LINE ADDED ### with ImageMagick 7.0.9-5 – La Muerte Peluda Mar 04 '20 at 09:00
10

With ImageMagic 7.0.10 on MacOs Catalina I have done the following which did the trick.

  • Edited /usr/local/Cellar/imagemagick/7.0.10-7/etc/ImageMagick-7/type.xml and replaced type-ghostscript with type-apple
  • Edited /usr/local/Cellar/imagemagick/7.0.10-7/etc/ImageMagick-7/type-apple.xml and added "/System/Library/Fonts/Supplemental" in front of all glyph paths
mtotschnig
  • 1,238
  • 10
  • 30