ImageMagick and imagick_type_gen don't recognize added fonts

Ok, I am running a CentOS server, PHP 5.4.440 and ImageMagick 6.5.4 and I am trying to add additional fonts like Lobster as an example. Here's what I've done so far:

Lobster.ttf uploaded to / home / myusername / fonts /

From SSH run "perl imagick_type_gen> fonts.xml". This resulted in a large font file, but contained no links to either Lobster.otf or Lobster.ttf

Instead, I generated my own type.xml and saved it to /home/myusername/.magick/. Here's the markup:

<?xml version="1.0"?>
    <type format="otf" name="Lobster" fullname="Lobster" family="Lobster" glyphs="/home/myusername/fonts/Lobster.otf" />


Through SSH, I edited / user / lib 64 / ImageMagick-6.5.4 / config / type.xml and inserted a node that references the custom .xml type:

    <include file="type-ghostscript.xml" />
    <include file="/home/myusername/.magick/type.xml" />


Reboot the server.

At this point, I can list the fonts using this:

$image = new Imagick();
$fonts = $image->queryfonts();
foreach($fonts as $font) {
    echo $font . '<br />';


And Lobster appears on the list. However, converting SVG to PNG does not use the Lobster font. I've seen other questions similar to mine and they seem to work. What do I need to do for the system to recognize the added font?

Here's the code I'm using to render what should be an image using Lobster as the font:

//Setup SVG to be read by Imagick.
$SVG = '<?xml version="1.0" encoding="utf-8"?>';
$SVG .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "">';
$SVG .= '<svg version="1.1" id="Layer_1" xmlns="" xmlns:xlink="" x="0px" y="0px" width="158px" height="92px" viewBox="0 0 158 92" enable-background="new 0 0 158 92" xml:space="preserve">';
$SVG .= '<text transform="matrix(1 0 0 1 32 58)" font-family="Lobster" font-style="normal" font-size="20px" font-weight="400">Lobster</text>';
$SVG .= '</svg>';

$image = new Imagick();

//Convert SVG to JPG

//Save the thumbnail.
$save_path = 'lobster-test.jpg';

echo '<img src="'.$save_path.'">';


I have a complete loss here. Help!


source to share

2 answers

The complete solution is covered here:

But here's the short version:

  • Create a directory for the custom downloaded fonts in / usr / share / fonts / default - I created a directory called "custom".
  • Copy the fonts you want to install to / usr / share / fonts / default / custom
  • Run command fc-cache -v / usr / share / fonts

After that ImageMagick will use the fonts in SVG. The only caveat is that you MUST use the font-family declaration built into the font. For example, Lobster.otf actually lists "Lobster 1.4".

If you have a font installed and use the correct font family name, you will have your fonts!



You need to install the fonts on your server and this is the only way I have managed to solve this problem.

You can check Eric Green's answer to this question.



All Articles