Annotation and Drawing

Image::Magick still sports some powerful drawing features that you may choose to use over GD’s simple drawing API (see Chapter 2). In particular, Image::Magick has better text annotation capabilities, allowing you to use TrueType, PostScript, and X11 fonts. Additionally, you can query the metrics of those fonts for information that is necessary for more complicated text layouts. Table 3-6 lists the attributes associated with drawing and annotation.

Table 3-6. Annotation and drawing attributes

Attribute

Read

Write

Description

antialias

Yes

Yes

If a true value, use antialiasing when drawing or annotating an image.

font

Yes

Yes

The text annotation methods Annotate( ) and Draw( ) require a font. This can be a fully qualified X11 font (e.g., -*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-*), TrueType (e.g., @TimesRoman.ttf), or PostScript (e.g., Helvetica) font name. Image::Magick requires access to an X11 server, FreeType library, and Ghostscript to render X11, TrueType, and PostScript fonts, respectively.

stroke

Yes

No

Methods Annotate( ) and Draw( ) require a stroke color.

pixel

Yes

Yes

The pixel attribute returns the red, green, blue, and opacity value (or colormap index for colormapped images) at the given coordinate as four decimal numbers separated by commas. For example, if an image has a white pixel at (20,50), the following code:

@pixel = split /,/,
$image->Get('pixel[20,50]');
print "Red: $pixel[0]\nGreen: $pixel[1]\nBlue: $pixel[2]\nOpacity: $pixel[3]\n";

will print the ...

Get Perl Graphics Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.