4

When trying to add annotations to images in ImageMagick, It failed with the following message:

convert: unable to read font `(null)' @ error/annotate.c/RenderFreetype...

How do I make Imagemagick find these fonts?

Adam Matan
  • 128,757
  • 147
  • 397
  • 562

3 Answers3

9

The solution that worked for me was given by Neville in this post:

  1. Create an imagemagick configuration folder: mkdir ~/.magick
  2. Save this Perl script as /tmp/script.pl
  3. Make the script executable: chmod +x /tmp/script.pl
  4. Run the script locally and redirect the output to the file type.xml in ~/.magick: /tmp/script.pl > ~/.magick/type.xml

This solved the fonts problem, while installing fondu, the imagemagick pkg file and some other tricks didn't.

Great! Now I can annotate some flickr cats with the image size and resolution (I want this for finding the optimal resolution for an app I'm working on).

enter image description here

enter image description here

enter image description here

Adam Matan
  • 128,757
  • 147
  • 397
  • 562
  • This unfortunately doesn't seem to get TTC fonts – Andrew B. Jan 13 '19 at 15:33
  • On OSX 10 I found I had to edit the script to include /System/Library/Fonts as well as /Library/Fonts. Change the find on line 482 from `find /Library/Fonts -type f -name '*.*'` to `find /Library/Fonts /System/Library/Fonts -type f -name '*.*'` – srkleiman Nov 06 '20 at 23:49
5

Adopting Adam Matan's answer, here's how I got this to work with imagemagick 7+ on macOS 10.12+ installed with homebrew. (This also assumes you have perl installed.)

  1. Download the perl script and save it to /usr/local/bin/imagick_type_gen

  2. Make the script executable:

    • chmod +x /usr/local/bin/imagick_type_gen
  3. Find the font path for imagemagick by running convert -list font | grep Path. This should return where imagemagick is looking for fonts. The Apple path for me was this:

    • /usr/local/Cellar/imagemagick/7.0.7-22/etc/ImageMagick-7/type-apple.xml
  4. Run imagick_type_gen and direct the output to the path above:

    • imagick_type_gen > /usr/local/Cellar/imagemagick/7.0.7-22/etc/ImageMagick-7/type-apple.xml
  5. Run convert -list font | less to see the font names imagemagick will use, e.g., some fonts will be labeled as GeorgiaB instead of Georgia Bold. (hit q to quit)

imagemagick should now see the fonts you have installed on the your system.

aboutaaron
  • 4,869
  • 3
  • 36
  • 30
  • 2
    This seems to get system-installed fonts, but not the many that I have installed as a user. The script doesn't seem to take any parameters to fix this either. How hard is to also check ~/Library/Fonts ? – John O Mar 05 '19 at 20:03
  • This worked for Homebrew; the accepted answer did not. Thanks. – btjakes Oct 29 '19 at 22:14
  • 1
    @badkya I installed Ghostscript (brew install gs) and then it did output a list of fonts. – Smek Feb 06 '20 at 08:17
  • 1
    @Smek `brew install gs` did the job for me, you should post it as an answer ;) – Jaroslaw Pawlak Mar 26 '20 at 12:19
  • 2
    Since Catalina, macOS fonts have moved so the script needs updating to look in `/System/Library/Fonts` - it occurs in two locations in the script (lines 478 and 482 at time of writing) – Chris May 23 '20 at 14:04
2

The easiest way to solve this issue is copying the font you need to a ~/ folder, or anywhere your script is, then give the direct path:

convert -font "~/MyFont.ttc"
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Paul
  • 21
  • 1