Alex Rivera | Logout

Specifying a font with the font family using ImageMagick

Asked 2012-05-14T03:26:06.257
11

Is it possible to render a font using the font family in ImageMagick?

I have tried everything I can think of and nothing seems to work. I have done a lot of searching and I can't seem to find anything that addresses this specific issue.

I am ultimately using PHP, but I have also tried using ImageMagick on the command line with no success. I am using ImageMagick 6.7.6 on linux. Here is what I have done so far.

  • I have tested the fonts that ImageMagick reckognizes using the identify -list font command
  • I have manually created a type.xml file based on the xml files that came installed on my system
  • I have created a type.xml file using this script: imagick_type_gen
  • I have tested with multiple font types: ttf, otf, pfb, ttc

Here is the example output from identify -list font for some fonts I have tested with:

Font: DejaVu-Sans-Book
  family: DejaVu Sans
  style: Normal
  stretch: Normal
  weight: 400
  glyphs: /usr/share/fonts/dejavu/DejaVuSans.ttf

Font: Baskerville-Regular
  family: Baskerville
  style: Normal
  stretch: Normal
  weight: 400
  glyphs: /usr/share/fonts/custom/Baskerville.ttc

Font: Palatino-Roman
  family: Palatino
  style: Normal
  stretch: Normal
  weight: 400
  glyphs: /usr/share/fonts/urw-fonts/p052003l.pfb

Font: Honey-Script-Light
  family: Honey Script
  style: Normal
  stretch: Normal
  weight: 300
  glyphs: /usr/share/fonts/custom/HoneyScript-Light.ttf


If I specify the full font name everything works as expected:

convert -pointsize 32 -font "Honey-Script-Light" label:'Testing' testing.png

Working


However, when I try to use the font family (both listed by identify -list font

Edit
Report

1 Answer

2

This is due to how font families work; for instance, the "Arial" font family comprises specific font definitions for bold, italic, underlines, etc. You must be specific when choosing a font to use in your images.

I'm guessing that if you really wanted to, you could do the following:

  1. Take the font family name, replace spaces with dashes
  2. If that works, great!
  3. If not, append -Regular to the end and try again

But you shouldn't do anything programmatic with font family unless you're forced to ;-)

My source of imagick knowledge mostly comes from this guy: http://valokuva.org/?cat=1

answered 2012-05-14T03:39:35.420

Your Answer