For Windows users all the True Type fonts installed on the system can be accessed by ImageMagick. As mentioned before you just need to know the right name of the font or the font family.
But Linux users need to change some settings for activating new fonts. If you specify a font in your command, ImageMagick searches it in the font configuration file, type.xml
.
Here is the order in which the search is done:
$MAGICK_CONFIGURE_PATH $MAGICK_HOME/lib/ImageMagick-6.2.4/config $MAGICK_HOME/share/ImageMagick-6.2.4/config $HOME/.magick/ <client path>/lib/ImageMagick-6.2.4/ <current directory>/ $MAGICK_FONT_PATH
Sometimes we need to add and install a new True Type font (TTF) on ImageMagick if you are a Linux user. Here are the required steps for doing this.
Copy the TTF font file to your server in the font directory (and make sure it has read and write permission).
Linux has a utility called ttf2pt1.exe
, which converts a TTF font file to suitable font files that can be used in the system. Use this utility as follows:
ttf2pt1 -e ARIAL.TTF arial
The output of this program is two files with .afm
and .pfa
extensions.
The arial.afm
file is used for metrics (size, stretch, and so on) and arial.pfa
is the font itself that is used in Linux.
In the next step copy the .pfa
and .afm
files to the Ghostscript font directories. First we need to find the directory, so enter the following command to list the directories where Ghostscript looks for fonts:
Gs -h
The output of that command may look like the following:
/usr/share/fonts/default/ghostscript/
Or:
usr/share/fonts/default/Type1/
Now refer to the Type-Ghostscript.xml
file and add a new entry to it for the new font files. For editing this file you can use the pico utility. As you can see, after the heading part in this file there are some<type>
tags, using which new fonts can be defined.
Here is an example :
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE typemap [ <!ELEMENT typemap (type+)> <!ELEMENT type (#PCDATA)> <!ELEMENT include (#PCDATA)> <!ATTLIST type name CDATA #REQUIRED> <!ATTLIST type fullname CDATA #IMPLIED> <!ATTLIST type family CDATA #IMPLIED> <!ATTLIST type foundry CDATA #IMPLIED> <!ATTLIST type weight CDATA #IMPLIED> <!ATTLIST type style CDATA #IMPLIED> <!ATTLIST type stretch CDATA #IMPLIED> <!ATTLIST type format CDATA #IMPLIED> <!ATTLIST type metrics CDATA #IMPLIED> <!ATTLIST type glyphs CDATA #REQUIRED> <!ATTLIST type version CDATA #IMPLIED> <!ATTLIST include file CDATA #REQUIRED> ]> <typemap> <type name="AvantGarde-Book" fullname="AvantGarde Book" family="AvantGarde" foundry="URW" weight="400" style="normal" stretch="normal" format="type1" metrics="@[email protected]" glyphs="@[email protected]" /> <type name="AvantGarde-BookOblique" fullname="AvantGarde Book Oblique" family="AvantGarde" foundry="URW" weight="400" style="oblique" stretch="normal" format="type1" metrics="@[email protected]" glyphs="@[email protected]" /> <type name="AvantGarde-Demi" fullname="AvantGarde DemiBold" family="AvantGarde" foundry="URW" weight="600" style="normal" stretch="normal" format="type1" metrics="@[email protected]" glyphs="@[email protected]" /> ... </typemap>
The new font should be ready to use now. Try the following command and see if it has been added to the ImageMagick default fonts:
identify -list type