Writes text on an image using the Type1 PostScript font specified by the font identifier. A number of parameters in this function require explanation.
The foreground and background colors are used for anti-aliasing, and it's a good idea to specify the same color for the text background as the background of the image so the anti-aliasing works correctly. You can create a halo text effect by specifying a different background color.
The X and Y coordinates define where the first character is drawn. This is taken from the lower-left corner of the first character.
spacing and tightness specify the distance between words and letters. spacing refers to the size of the space between words; tightness refers to the spacing between individual letters. These are expressed in character space units, where 1 unit is 1/1000th of an em-square.
Anti-aliasing refers to the smoothing of round text edges. There are only two values for this, 4 and 16, which refer to low and high, respectively. If you're using smaller font sizes, use a value of 16. For large font sizes, use 4. Although you can use either size at any time, a small font size with less anti-aliasing yields poorer text quality; a high anti-alias value with large text can be computationally expensive.
The array returned contains the coordinates of the bounding box surrounding the text. The coordinate numbering starts relative to the lower left of the text and moves to the upper right.
header("content-type: image/png"); $text="hello world"; $font = imagepsloadfont("/path/to/font.pfb"); $im = imagecreate(200, 200); $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); $green = imagecolorallocate($im, 0, 255, 0); imagefill($im, 0, 0, $black); $bound = imagepstext($im, $text, $font, 25, $white, $green, 10, 100, 0, 0, 0, 4); imagestring($im, 2, 10, 10, "x1 " . $bound, $white); imagestring($im, 2, 10, 20, "y1 " . $bound, $white); imagestring($im, 2, 10, 30, "x2 " . $bound, $white); imagestring($im, 2, 10, 40, "y2 " . $bound, $white); 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.