PHP Manual
Prev |  | Next

# imagettftext

(PHP 3, PHP 4 )

imagettftext -- Write text to the image using TrueType fonts

## Description

array imagettftext ( resource image, int size, int angle, int x, int y, int col, string fontfile, string text)

imagettftext() draws the string `text` in the image identified by `image`, starting at coordinates `x`, `y` (top left is 0, 0), at an angle of `angle` in color `col`, using the TrueType font file identified by `fontfile`. Depending on which version of the GD library that PHP is using, when `fontfile` does not begin with a leading '/', '.ttf' will be appended to the filename and the the library will attempt to search for that filename along a library-defined font path.

The coordinates given by `x`, `y` will define the basepoint of the first character (roughly the lower-left corner of the character). This is different from the imagestring(), where x, y define the upper-right corner of the first character.

`Angle` is in degrees, with 0 degrees being left-to-right reading text (3 o'clock direction), and higher values representing a counter-clockwise rotation. (i.e., a value of 90 would result in bottom-to-top reading text).

`Fontfile` is the path to the TrueType font you wish to use.

`Text` is the text string which may include UTF-8 character sequences (of the form: &#123;) to access characters in a font beyond the first 255.

`Col` is the color index. Using the negative of a color index has the effect of turning off antialiasing.

imagettftext() returns an array with 8 elements representing four points making the bounding box of the text. The order of the points is lower left, lower right, upper right, upper left. The points are relative to the text regardless of the angle, so "upper left" means in the top left-hand corner when you see the text horizontallty.

This example script will produce a black GIF 400x30 pixels, with the words "Testing..." in white in the font Arial.

Example 1. imagettftext
    <?php
    header ("Content-type: image/gif");
    $im = imagecreate (400, 30);
    $black = imagecolorallocate ($im, 0, 0, 0);
    $white = imagecolorallocate ($im, 255, 255, 255);
    imagettftext ($im, 20, 0, 10, 20, $white, "/path/arial.ttf", "Testing...Omega: &#937;");
    imagegif ($im);
    imagedestroy ($im);
    ?>

This function requires both the GD library and the FreeType library.

See also imagettfbbox().

Prev | Home | Next
imagettfbbox | Up | imagetypes