|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-05-16 09:31 UTC] ab@php.net
[2013-05-16 09:31 UTC] ab@php.net
-Status: Open
+Status: Feedback
[2013-05-16 10:31 UTC] gert-rainer dot bitterlich at ima-dresden dot de
-Status: Feedback
+Status: Open
[2013-05-16 10:31 UTC] gert-rainer dot bitterlich at ima-dresden dot de
[2013-05-16 10:54 UTC] ab@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: ab
[2013-05-16 10:54 UTC] ab@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 13:00:02 2025 UTC |
Description: ------------ The function imagettfbbox(...) calculates wrong result with PHP 5.5.0RC1. With older PHP Version the result is correct. Test script: --------------- <?php function calculateTextBox($text,$fontFile,$fontSize,$fontAngle) { /************ simple function that calculates the *exact* bounding box (single pixel precision). The function returns an associative array with these keys: left, top: coordinates you will pass to imagettftext width, height: dimension of the image you have to create *************/ $rect = imagettfbbox($fontSize,$fontAngle,$fontFile,$text); $minX = min(array($rect[0],$rect[2],$rect[4],$rect[6])); $maxX = max(array($rect[0],$rect[2],$rect[4],$rect[6])); $minY = min(array($rect[1],$rect[3],$rect[5],$rect[7])); $maxY = max(array($rect[1],$rect[3],$rect[5],$rect[7])); return array( "left" => abs($minX) - 1, "top" => abs($minY) - 1, "width" => $maxX - $minX, "height" => $maxY - $minY, "box" => $rect ); } // Example usage - gif image output $text_string = "Hello World"; $font_ttf = "c:/windows/fonts/arial.ttf"; $font_size = 22; $text_angle = 0; $text_padding = 10; // Img padding - around text $the_box = calculateTextBox($text_string, $font_ttf, $font_size, $text_angle); echo'<pre>';print_r($the_box);echo'</pre>'; ?> Expected result: ---------------- Array ( [left] => 0 [top] => 21 [width] => 149 [height] => 21 [box] => Array ( [0] => -1 [1] => -1 [2] => 148 [3] => -1 [4] => 148 [5] => -22 [6] => -1 [7] => -22 ) ) Actual result: -------------- Array ( [left] => 1729848214 [top] => -1 [width] => 3723327540 [height] => 1993479376 [box] => Array ( [0] => 1993479325 [1] => 1716 [2] => 0 [3] => 1993479376 [4] => -1729848215 [5] => 0 [6] => 0 [7] => 1516706532 ) )