Book Image

ImageMagick Tricks

By : Sohail Salehi
Book Image

ImageMagick Tricks

By: Sohail Salehi

Overview of this book

<p>The book is packed with interesting and fun examples. We had a lot of fun coming up with cool ways to demonstrate ImageMagick's power, and we're sure you'll have fun learning how to create them.<br /><br />Although the printed book is in black and white, there is a full colour PDF of the screenshots freely available that includes all of the images in the book. Use it to see exactly what the ImageMagick effects look like in colour, or browse through it and see just what you'll learn to do with this book.<br /><br />ImageMagick is a free software suite to create, edit, and compose bitmap images using text-based commands. The commands can be issued from the command line, but more often will be included in web or desktop applications &acirc;&euro;&ldquo; carrying out complex image-manipulation tasks in response to the user's input.<br /><br />ImageMagick is a popular way for generating images on-the-fly in web pages, whether it's generating thumbnails from a large image, or creating complex combinations of images, text, and effects chosen by a visitor or the web site's creator.</p>
Table of Contents (18 chapters)
ImageMagick Tricks
Credits
About the Author
About the Reviewers
Preface
5
Identify, Display, and Import
Index

How to Define New Fonts for ImageMagick


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