convert unable to read font

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Locked
stretch
Posts: 1
Joined: 2018-10-21T07:23:59-07:00
Authentication code: 1152

convert unable to read font

Post by stretch »

Hi

I'm trying to run convert on my ubuntu box and i'm getting

convert -background white -pointsize 20 -gravity center label:"test" /var/www/html/test.png

Code: Select all

convert-im6.q16: unable to read font `(null)' @ error/annotate.c/RenderFreetype/1362.
convert-im6.q16: no images defined `/var/www/html/hello.png' @ error/convert.c/ConvertImageCommand/3258.
convert -list font

Code: Select all

Path: System Fonts
  Font: DejaVu-Sans
    family: DejaVu Sans
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
  Font: DejaVu-Sans-Bold
    family: DejaVu Sans
    style: Normal
    stretch: Normal
    weight: 700
    glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf
  Font: DejaVu-Sans-Mono
    family: DejaVu Sans Mono
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf
  Font: DejaVu-Sans-Mono-Bold
    family: DejaVu Sans Mono
    style: Normal
    stretch: Normal
    weight: 700
    glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf
  Font: DejaVu-Serif
    family: DejaVu Serif
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf
  Font: DejaVu-Serif-Bold
    family: DejaVu Serif
    style: Normal
    stretch: Normal
    weight: 700
    glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf
  Font: FontAwesome
    family: FontAwesome
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /usr/share/fonts/truetype/font-awesome/fontawesome-webfont.ttf
also tried

apt-get install ghostscript

Code: Select all

Reading package lists... Done
Building dependency tree
Reading state information... Done
ghostscript is already the newest version (9.25~dfsg+1-0ubuntu0.18.04.1).
If you don't specify a font what one is used by default?

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert unable to read font

Post by fmw42 »

If you don't specify a font what one is used by default?
I think it relies on the system default font, but am not 100% sure of that. In the font family documentation https://imagemagick.org/script/command- ... php#family it seems to say it is Arial. But that only works if you have arial on your system. You do not seem to have any default set. I know little about Linux, but on my Mac, it is Arial.

One can find the default, if it is set by adding -debug annotate to your command:

Code: Select all

convert -debug annotate -background white -pointsize 20 -gravity center label:"test" null:
But why would you rely upon some default font? You should always provide the font you want by name if it is set in your type.xml file or by path to the font file. -font arial or -font /path/to/arial.ttf

See https://imagemagick.org/script/resources.php for the type.xml file.

See https://imagemagick.org/Usage/scripts/imagick_type_gen for a script to load all the appropriate fonts on your system into the type.xml file so you can reference them by name.

You can also specify MAGICK_FONT_PATH. See https://imagemagick.org/script/resources.php

taxisaga
Posts: 15
Joined: 2018-07-10T11:13:28-07:00
Authentication code: 1152
Location: Sunnyvale, CA

Re: convert unable to read font

Post by taxisaga »

It seems things have changed a bit in newer versions of macOS. The fonts are now in /System/Library/Fonts, so the few references to /Library/Fonts in that script need to be changed for it to work.

Here's what worked for me on macOS Catalina:

Get the imagick_type_gen script referenced above

IFF running the script gives you no output on your older macOS system, then edit and save the script, changing mentions
of /Library/Fonts to instead say /System/Library/Fonts

after editing, set the bit to make the file executable:

Code: Select all

chmod +x imagick_type_gen
make a config directory for ImageMagick:

Code: Select all

mkdir -p ~/.magick
run the script and redirect output to file "type.xml" in that new directory:

Code: Select all

./imagick_type_gen > ~/.magick/type.xml
(did not work without this step) set an environment variable pointing to that directory, in .bashrc

Code: Select all

export MAGICK_CONFIGURE_PATH=~/.magick
(I'm not saying that fmw42's steps would not work... I didn't try the MAGICK_FONT_PATH variable.)

source the .bashrc file to make the environment variable take effect the first time:

Code: Select all

source ~/.bashrc
(subsequent times after you restart the terminal, the variable should take effect automatically without this).

test:

Code: Select all

convert -list font
(should see a list of fonts, which confirms the listed fonts can now be used. If no list appears, something went wrong.)

Locked