[php-maint] Bug#561571: Wrong X-coordinate calculation in imagettfbbox function of php5

Максим Максим
Fri Dec 18 10:25:09 UTC 2009


Package: libapache2-mod-php5
Version: 5.2.11.dfsg.1-2

Package: libgd2-xpm
Version: 2.0.36~rc1~dfsg-3.1

When site being opened first time function imagettfbbox calculates wrong 
X-coordinate.
As a result we seen only "And Zend Engine ..." string. If I refresh 
site, coordintes calculates correct and I'll see both sign "Powere by 
PHP" and "And Zend Optimizer

There is test script:

<?php^M
// Create a 300x150 image^M
$im = imagecreatetruecolor(300, 150);^M
$black = imagecolorallocate($im, 0, 0, 0);^M
$white = imagecolorallocate($im, 255, 255, 255);^M

// Set the background to be white^M
imagefilledrectangle($im, 0, 0, 299, 299, $white);^M

// Path to our font file^M
$font = $_SERVER["DOCUMENT_ROOT"].'/bitrix/modules/main/fonts/font.ttf';^M

// First we create our bounding box for the first text^M
$bbox = imagettfbbox(10, 45, $font, 'Powered by PHP ' . phpversion());^M

// This is our cordinates for X and Y^M
$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 25;^M
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;^M
var_dump($x);
var_dump($y);
die;

// Write it
imagettftext($im, 10, 45, $x, $y, $black, $font, 'Powered by PHP ' . 
phpversion());^M

// Create the next bounding box for the second text^M
$bbox = imagettfbbox(10, 45, $font, 'and Zend Engine ' . zend_version());^M

// Set the cordinates so its next to the first text^M
$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) + 10;^M
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;^M

// Write it^M
imagettftext($im, 10, 45, $x, $y, $black, $font, 'and Zend Engine ' . 
zend_version());^M

// Output to browser^M
header('Content-type: image/png');^M

imagepng($im);^M
imagedestroy($im);^M
?>

This is a result of var_dump, when firstly opened:
int(1073741950) int(139)
and after site refresh:
float(69.5) int(139)

I'm using Debian 'squeeze':
Linux 2.6.31-1-686 #1 SMP Sun Nov 15 20:39:33 UTC 2009 i686 GNU/Linux
 







More information about the pkg-php-maint mailing list