ImageMagick "convert" command cannot use fonts!

18,434

Solution 1

Arial is not a free font. Its terms of use on open source platforms like Linux and Ubuntu make it impossible to distribute as part of an installation. You should use one of the free/open alternatives such as Liberation.

You can list the fonts you have with convert -list font. Eg:

$ convert -list font|grep Liberation-Sans
Font: Liberation-Sans-Bold
Font: Liberation-Sans-Bold-Italic
Font: Liberation-Sans-Italic
Font: Liberation-Sans-Narrow-Bold
Font: Liberation-Sans-Narrow-Bold-Italic
Font: Liberation-Sans-Narrow-Italic
Font: Liberation-Sans-Narrow-Regular
Font: Liberation-Sans-Regular

Solution 2

I got the same problem with my Macbook today. The cause of that is a simple one.

convert uses only known fonts. All known fonts to convert are listed with this command.

convert -list font

My desired font was in ~/Library/Fonts. convert didn't list it.

I followed the instructions from Mark Setchell and was capable generating my type.xml.

The entry for my font in type.xml

<type format="ttf"
  name="MyriadPro"
  fullname="MyriadPro-Regular"
  family="Myriad Pro" 
  glyphs="/Users/vinh/Library/Fonts/myriadpro-regular.ttf"/> 

I can use the name or the absolute path to generate my image.

convert -size 300x50 xc:none -font "MyriadPro" \
  -pointsize 20 -kerning 1 -gravity center \
  -fill black -annotate 0x0+0+0 "mimacom" \
  -fill white -annotate 0x0+2+2 "mimacom" mimacom.png
Share:
18,434
PHP Learner
Author by

PHP Learner

I decided to create a web site of my self, using PHP language. While learning PHP, I became familiar with Linux and Ubuntu and find it better than Microsoft Windows. Now trying to learn both PHP and Linux (Ubuntu) simultaneously.

Updated on September 18, 2022

Comments

  • PHP Learner
    PHP Learner over 1 year
    convert -size 300x50 xc:none -font Arial -pointsize 20 -gravity center -draw "fill white text 1,1 \"$1\" text 0,0 \"$1\" fill black text -1,-1 \"$1\"" $WATERMARK_FILE
    

    Above command results following error:

    convert.im6: unable to read font `Arial' @ warning/annotate.c/RenderType/853.
    

    I searched the web and find that many users saw this error, but did not find any solution. Can anyone help?

    NOTE 1: Arial font is installed on my system:

    $ fc-list | grep -i arial
    /usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf: Arial:style=Italic,Cursiva,kurzíva,kursiv,Πλάγια,Kursivoitu,Italique,Dőlt,Corsivo,Cursief,Kursywa,Itálico,Курсив,İtalik,Poševno,nghiêng,Etzana
    /usr/share/fonts/truetype/msttcorefonts/ariblk.ttf: Arial Black:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
    /usr/share/fonts/truetype/msttcorefonts/Arial.ttf: Arial:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,thường,Arrunta
    /usr/share/fonts/truetype/msttcorefonts/arialbd.ttf: Arial:style=Bold,Negreta,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,đậm,Lodia
    /usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf: Arial:style=Bold Italic,Negreta cursiva,tučné kurzíva,fed kursiv,Fett Kursiv,Έντονα Πλάγια,Negrita Cursiva,Lihavoitu Kursivoi,Gras Italique,Félkövér dőlt,Grassetto Corsivo,Vet Cursief,Halvfet Kursiv,Pogrubiona kursywa,Negrito Itálico,Полужирный Курсив,Tučná kurzíva,Fet Kursiv,Kalın İtalik,Krepko poševno,nghiêng đậm,Lodi etzana
    /usr/share/fonts/truetype/msttcorefonts/arialbi.ttf: Arial:style=Bold Italic,Negreta cursiva,tučné kurzíva,fed kursiv,Fett Kursiv,Έντονα Πλάγια,Negrita Cursiva,Lihavoitu Kursivoi,Gras Italique,Félkövér dőlt,Grassetto Corsivo,Vet Cursief,Halvfet Kursiv,Pogrubiona kursywa,Negrito Itálico,Полужирный Курсив,Tučná kurzíva,Fet Kursiv,Kalın İtalik,Krepko poševno,nghiêng đậm,Lodi etzana
    /usr/share/fonts/truetype/msttcorefonts/Arial_Black.ttf: Arial Black:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
    /usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf: Arial:style=Bold,Negreta,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,đậm,Lodia
    /usr/share/fonts/truetype/msttcorefonts/ariali.ttf: Arial:style=Italic,Cursiva,kurzíva,kursiv,Πλάγια,Kursivoitu,Italique,Dőlt,Corsivo,Cursief,Kursywa,Itálico,Курсив,İtalik,Poševno,nghiêng,Etzana
    

    NOTE 2: Changing the case in font name (arial instead of Arial)does not help.

    NOTE 3: Using absolute font file path with complete font file name (filename.fileextension) removes the error:

    convert -size 300x50 xc:none -font "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf" -pointsize 20 -gravity center -draw "fill white text 1,1 \"$1\" text 0,0 \"$1\" fill black text -1,-1 \"$1\"" $WATERMARK_FILE
    
    • Jacob Vlijm
      Jacob Vlijm over 8 years
      Before posting as an answer: I solved it by using absolute path to the font in question. Not sure why though. Let me know if it works :)
    • terdon
      terdon over 8 years
      Please edit your question and post the output of fc-list | grep -i arial. The command you show worked for me with no error. Do you have Arial installed?
    • Jacob Vlijm
      Jacob Vlijm over 8 years
      @terdon, on Ubuntu, this is a common issue. Never found an explanation though.
    • terdon
      terdon over 8 years
      @JacobVlijm presumably, it's something about the name of the font in the font-cache then. Perhaps it needs lowercase arial or the name is slightly different. You also need to have the msttcorefonts installed, I think.
    • Jacob Vlijm
      Jacob Vlijm over 8 years
      @terdon When I ran into it (was something for Parto: askubuntu.com/questions/552456/…) I tried everything: upper/lowercase, also all types of fonts with no luck. On some post (not AU) I ran into the suggestion to use absolute paths. Worked, without the satisfaction of understanding why.
    • Jacob Vlijm
      Jacob Vlijm over 8 years
      Hi php, could you mention if it works?
    • PHP Learner
      PHP Learner over 8 years
      The information you asked for is added to my question.
    • badp
      badp over 6 years
      Please move your note #3 to its own answer :)
  • Jacob Vlijm
    Jacob Vlijm over 8 years
    I can assure you, it has nothing to do with that. All fonts work if absolute paths are used. Did you try?
  • PHP Learner
    PHP Learner over 8 years
    Dear meuh, it is not related to font license or copyright. It is just related to font name in my system. Your answer guided me to use $ convert -list font | grep "Font:" | grep Arial command and it resulted: Font: Arial-Black-Regular Font: Arial-Bold Font: Arial-Bold-Italic Font: Arial-Italic Font: Arial-Regular. Thus I understand that I must use "Arial-Regular" instead of "Arial" as font name. Please update your answer!
  • theonlygusti
    theonlygusti about 4 years
    That list is empty