Name

string( ) — draw a text string on an image

Synopsis

GD::Image::string(font, x, y, string, color)

The string( ) method draws the string onto the image with the upper left corner of the text box starting at the coordinate x, y. The font must be one of the six GD fonts: gdTinyFont, gdSmallFont, gdMediumBoldFont, gdLargeFont, or gdGiantFont.

To draw a string with quotes in it, escape the quotes with a backslash (\). Because of its limited font support, GD does not interpret escaped linefeeds (or other special characters) the way that ImageMagick does. Multiple lines of text must be drawn as separate strings, with the space between lines computed using the GD::Font::heightobject method. You may want to consider using ImageMagick for creating text-intensive graphics anyway, as its font support is more robust than GD’s font support.

An example:

$image->string(gdTinyFont,10, 10,"A way a lone a last a loved a long the", $red);

Get Programming Web Graphics with Perl and GNU Softwar 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.