From: lbayuk at pobox dot com Operating system: Linux PHP version: 5.2.4 PHP Bug Type: GD related Bug description: TrueType bounding box is wrong for angle<>0
Description: ------------ The bounding box returned from imagettfbbox() and imagettftext() is incorrect for anything except horizontal text at 0 degrees. For all other angles, the text is partially or completely outside the returned bounding box. (Yes, somebody reported the same problem in #37730, but that was marked "no feedback" and is not getting any attention. Could someone please-please look at this issue?) The PHP script below demonstrates. Using the bundled GD library, and any TrueType font. Change $font to point to any TrueType font file you have. Run via PHP CLI, sending out to filename.png and view, or access via browser. I wrote an equivalent C program with gd-2.0.35 (Slackware 12.0 Linux distribution), and the bounding boxes are correct. So there is probably something wrong in the GD library bundled with PHP. Reproduce code: --------------- <?php $font = '/usr/share/fonts/TTF/luximr.ttf'; # Full path to any TTF Font $delta_t = 360.0 / 16; # Make 16 steps around $g = imagecreate(800, 800); $bgnd = imagecolorallocate($g, 255, 255, 255); $black = imagecolorallocate($g, 0, 0, 0); $x = 100; $y = 0; $cos_t = cos(deg2rad($delta_t)); $sin_t = sin(deg2rad($delta_t)); for ($angle = 0.0; $angle < 360.0; $angle += $delta_t) { $bbox = imagettftext($g, 24, $angle, 400+$x, 400+$y, $black, $font, 'ABCDEF'); imagepolygon($g, $bbox, 4, $black); imagefilledellipse($g, $bbox[0], $bbox[1], 8, 8, $black); $temp = $cos_t * $x + $sin_t * $y; $y = $cos_t * $y - $sin_t * $x; $x = $temp; } header("Content-type: image/png"); imagepng($g); Expected result: ---------------- In the image output: For each angle of text, the box should enclose the text, with the dot to the lower left (relative to the text baseline) of the first character in the string. Actual result: -------------- The bounding box for 0 degree text is correct. All the others are off by different amounts. Worst is the text between 180 and 270 degrees, where the text is completely outside the bounding box. -- Edit bug report at http://bugs.php.net/?id=43073&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43073&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43073&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43073&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43073&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43073&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43073&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43073&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43073&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43073&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43073&r=support Expected behavior: http://bugs.php.net/fix.php?id=43073&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43073&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43073&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43073&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43073&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43073&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43073&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43073&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43073&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43073&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43073&r=mysqlcfg