imagettftext() relies on Freetype support being compiled into PHP. The function draws a string on the image in a specified TrueType font. There are several advantages to using this function versus imagestring() : Any TrueType font file can be used, the text can be rotated at any angle, and the font size can be more widely varied. The angle of rotation of the text is different from that used by imagearc() . The rotation point is the x and y coordinate position at the lower-left corner of the first character. From there, the angle goes from 0 to 360 degrees up and around to the left in a counterclockwise direction. The function returns an eight-element array consisting of the x and y coordinates of the bounding box (the rectangle enclosing the rendered text). The coordinates are independent of the angle of rotation of the text. Thus, if the image is rotated, the coordinates are taken as the upper-left corner of the box around the text relevant to the text, not the upper-left corner of the rotated string.
The array returned from this function contains the bounding coordinates of the text. For more details, see imagettfbbox() .
header("Content-type: image/png"); $im = imagecreate(200, 200); $green = imagecolorallocate($im, 0, 255, 0); $red = imagecolorallocate($im, 255, 0, 0); imagefill($im, 0, 0, $green); imagettftext($im, 30, 45, 50, 150, $red, "verdana.ttf", "SAMPLE!"); imagepng($im); imagedestroy($im);
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.