Bug #64856 [Fbk->Opn]: Wrong results with imagettfbbox(..)
| From: | gert-rainer dot bitterlich at ima-dresden dot de | Date: | Thu, 16 May 2013 10:31:24 +0000 |
| Subject: | Bug #64856 [Fbk->Opn]: Wrong results with imagettfbbox(..) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-178965@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64856&edit=1
ID: 64856
User updated by: gert-rainer dot bitterlich at ima-dresden dot de
Reported by: gert-rainer dot bitterlich at ima-dresden dot de
Summary: Wrong results with imagettfbbox(..)
-Status: Feedback
+Status: Open
Type: Bug
Package: GD related
Operating System: Windows 7 Pro
PHP Version: 5.5.0RC1
Block user comment: N
Private report: N
New Comment:
With developer version http://windows.php.net/downloads/snaps/php-5.5/r07bd1fa/
it works correct now. Thank You.
Previous Comments:
------------------------------------------------------------------------
[2013-05-16 09:31:35] ab@php.net
This should have been fixed yesterday, please test this
http://windows.php.net/downloads/snaps/php-5.5/r07bd1fa/
or any later snap.
Thanks.
------------------------------------------------------------------------
[2013-05-16 09:09:09] gert-rainer dot bitterlich at ima-dresden dot de
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
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64856&edit=1