ID: 21560 Comment by: jtopland at hive dot no Reported By: ljpersson at hotmail dot com Status: Wont fix Bug Type: GD related Operating System: SusE 8.0,SuSE 8.2 PHP Version: 4.3.1-dev, 4.3.2RC2, 4.3.2RC3 Assigned To: pajoye New Comment:
Here's a fixed version of imagettfbbox(). All angles returns correct values. Except that imagettftext() returns different trackings (space between each character) when rotating. <?php // Set some test variables $font = "d://www//tahoma.ttf"; $text = "Finally, I can center rotated text!"; $size = 20; $angle = 20; // Create an image and fill the background with lightgray $image = imagecreatetruecolor(500, 400); imagefill($image, 0, 0, hexdec("dddddd")); // Make a cross to make it easier to analyze imageline($image, 0, 0, imagesx($image), imagesy($image), hexdec("000000")); imageline($image, imagesx($image), 0, 0, imagesy($image), hexdec("000000")); // Run a fixed version of imagettfbbox() $bbox = imagettfbbox_fixed($size, $angle, $font, $text); // Make some text and center the text on the image. // imagettftext() pivot is on lower left imagettftext($image, $size, $angle, imagesx($image) / 2 - $bbox['width'] / 2, imagesy($image) / 2 + $bbox['height'] / 2, hexdec("0000ff"), $font, $text); // Show the image imagepng($image); function imagettfbbox_fixed($size, $angle, $font, $text) { // Get the boundingbox from imagettfbbox(), which is correct when angle is 0 $bbox = imagettfbbox($size, 0, $font, $text); // Rotate the boundingbox $angle = pi() * 2 - $angle * pi() * 2 / 360; for ($i=0; $i<4; $i++) { $x = $bbox[$i * 2]; $y = $bbox[$i * 2 + 1]; $bbox[$i * 2] = cos($angle) * $x - sin($angle) * $y; $bbox[$i * 2 + 1] = sin($angle) * $x + cos($angle) * $y; } // Variables which tells the correct width and height $bbox['width'] = $bbox[0] + $bbox[4]; $bbox['height'] = $bbox[1] - $bbox[5]; return $bbox; } ?> Previous Comments: ------------------------------------------------------------------------ [2003-08-11 14:39:37] [EMAIL PROTECTED] There are BC issues with FT1 support in gd. The code requires deep changes to solve this issue. pierre ------------------------------------------------------------------------ [2003-07-20 03:29:03] kyle at putnamcabinets dot com I've upgraded to PHP 4.3.3RC1 and the problem still exists. Maybe a problem with GD? I've reported the bug to boutell.com and haven't recieved a response in over three weeks. An exmple of this bug at work (problem with imagettfbbox and imagettftext): http://webdev.quiteuseless.com/damn-gd-ttf-bugs/test.php ------------------------------------------------------------------------ [2003-06-24 01:33:35] kyle at putnamcabinets dot com I also experience the problem with PHP 4.3.2 and bundled GD version '2.0.12 compatible'. Recompiled with Debian package version (2.0.12-2... damn!) and same problem (obviously). It seems to be some how proportional to the angle of the text; smaller angles yield more accuracy. My implementation: <? $res = imagecreatetruecolor(400, 400); $white = imagecolorallocate($res, 0xff, 0xff, 0xff); $red = imagecolorallocate($res, 0xcc, 0x00, 0x00); $blue = imagecolorallocate($res, 0x00, 0x00, 0xcc); imagefill($res, 0, 0, $white); for ($angle = 0; $angle < 360; $angle += 60) { $wrong1 = imagettftext($res,20,$angle,200,200,$blue, "/usr/share/fonts/truetype/Courier_New.ttf", "ABCDEF 12345"); $t = imagettfbbox(20, $angle, "/usr/share/fonts/truetype/Courier_New.ttf", "ABCDEF 12345"); $wrong2 = array(200+$t[0],200+$t[1],200+$t[2], 200+$t[3],200+$t[4],200+$t[5],200+$t[6],200+$t[7]); imagepolygon($res,$wrong2,count($wrong2)/2,$red); imagepolygon($res,$wrong1,count($wrong1)/2,$red); } header("Content-type: image/png"); imagepng($res); ?> ------------------------------------------------------------------------ [2003-06-18 03:03:12] guno at guno dot nl I'm experiencing the same problem, using php 4.3.2 with GD 2.0.15 Normal text (with no rotation) results in a correct bounding box, but as soon as I rotate the text, it goes wrong, no matter which font I use. Here's a sample code which displays a text with it's bounding box at 0, 90, 180 and 170 degrees: <?php $image=imagecreate(500, 500); $imagedum=imagecreate(500, 500); $color1=imagecolorallocate($image, 0xff, 0xff, 0xff); $color2=imagecolorallocate($image, 0x3f, 0x3f, 0x3f); $color3=imagecolorallocate($image, 0xff, 0x00, 0x00); for ($angle=0; $angle<360; $angle+=90) { $text="ABCpqrs"; $font = "./verdana.ttf"; // Draw the text into the image: $result=imagettftext($imagedum, 30, $angle, 250, 250, $color2, $font, $text); imagettftext($image, 30, $angle, 250, 250, $color2, $font, $text); // Draw the bounding-box into the image: imageline($image, $result[0], $result[1], $result[2], $result[3], $color3); imageline($image, $result[2], $result[3], $result[4], $result[5], $color3); imageline($image, $result[4], $result[5], $result[6], $result[7], $color3); imageline($image, $result[6], $result[7], $result[0], $result[1], $color3); } // Draw the image to the screen: header("Content-Type: image/jpeg"); imagejpeg($image); imagedestroy($image); imagedestroy($imagedum); ?> ------------------------------------------------------------------------ [2003-05-16 19:37:07] ljpersson at hotmail dot com Just checked with 4.3.2RC3 and the problem still exists. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/21560 -- Edit this bug report at http://bugs.php.net/?id=21560&edit=1