php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51315 imagettfbbox randomly don't work
Submitted: 2010-03-17 20:55 UTC Modified: 2016-10-02 04:22 UTC
Votes:18
Avg. Score:4.5 ± 0.6
Reproduced:16 of 17 (94.1%)
Same Version:6 (37.5%)
Same OS:9 (56.2%)
From: administrateur at exinsidephp dot com Assigned: cmb
Status: No Feedback Package: GD related
PHP Version: 5.3.2 OS: Debian GNU/Linux 5.0
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-03-17 20:55 UTC] administrateur at exinsidephp dot com
Description:
------------
Hi,

I have ugraded PHP 5.2 to PHP 5.3.2 on my Debian server and I have found a bug width ths function imagettfbbox.

Sometimes the text don't show on the image generated :

http://www.exinsidephp.com/cache/example.png

If I refresh the page (Ctrl+F5) another image don't display the text :

http://www.exinsidephp.com/cache/example2.png

Any error on PHP Blog, any error on syslog or kernel log... I haven't find any trace of error. Someone have the same issue ?

The PHP Package come from http://www.dotdeb.org/ website. The list of modules installed (dpkg -l | grep php5) :

ii  libapache2-mod-php5 5.3.2-0.dotdeb.1                                                                
ii  php5                                 5.3.2-0.dotdeb.1                                                                
ii  php5-cli                                5.3.2-0.dotdeb.1                                                                
ii  php5-common                             5.3.2-0.dotdeb.1                                                                
ii  php5-curl                               5.3.2-0.dotdeb.1                                                                
ii  php5-dev                                5.3.2-0.dotdeb.1                                                                
ii  php5-gd                                 5.3.2-0.dotdeb.1                                                                
ii  php5-geoip                              5.3.2-0.dotdeb.1                                                                
ii  php5-imagick                            5.3.2-0.dotdeb.1                                                                
ii  php5-imap                               5.3.2-0.dotdeb.1                                                                
ii  php5-mcrypt                             5.3.2-0.dotdeb.1                                                                
ii  php5-mysql                              5.3.2-0.dotdeb.1                                                                
ii  php5-suhosin                            5.3.2-0.dotdeb.1                                                                
ii  php5-xcache                             5.3.2-0.dotdeb.1                                                                

Test script:
---------------
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Content-Type: image/png');
		
$image = imagecreate(55,15);
imagecolorallocate($image, 0,0,0);

if($get->getValue('temp2'))
	$texte = $get->getValue('temp1').'/'.$get->getValue('temp2').' °C';
else
	$texte = $get->getValue('temp1').' °C';

$tab = imagettfbbox(8,0,Config::getCons('PATH_CACHE').'font/verdana.TTF', $texte);
$text_x = (55-($tab[2]-$tab[6]))/2;
$text_y = (15-($tab[1]-$tab[5]))/2+9;

//$color = imagecolorallocate($image, 2,119,186);
$color = imagecolorallocate($image, 255,255,255);
imagettftext($image,8,0,$text_x,$text_y,$color,Config::getCons('PATH_CACHE').'font/verdana.TTF',$texte);

imagepng($image);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-19 16:26 UTC] administrateur at exinsidephp dot com
-Summary: imagettfbbox randomly don't work +Summary: imagettftext randomly don't work
 [2010-03-19 16:26 UTC] administrateur at exinsidephp dot com
Change title of bug
 [2010-03-19 16:35 UTC] administrateur at exinsidephp dot com
So I have add debug line and i find origin of bug :

View my previous script an modify width this line :

$tab = imagettfbbox(8,0,Config::getCons('PATH_CACHE').'font/verdana.TTF', $texte);
$text_x = (55-($tab[2]-$tab[6]))/2;
$text_y = (15-($tab[1]-$tab[5]))/2+9;

file_put_contents(Config::getCons('PATH_CACHE').'log_font.txt', $text.' x:'.$text_x.' y:'.$text_y.' imagbox:'.json_encode($tab)."\n",FILE_APPEND);


The result : 

 x:12 y:12.5 imagbox:[-1,-1,30,-1,30,-9,-1,-9]
 x:33554459 y:12.5 imagbox:[-1,-1,-33554433,-1,-33554433,-9,33554430,-9]
 x:33554459 y:12.5 imagbox:[-1,-1,-33554433,-1,-33554433,-9,33554430,-9]
 x:33554459 y:12.5 imagbox:[-1,-1,-33554433,-1,-33554433,-9,33554430,-9]
 x:12 y:12.5 imagbox:[-1,-1,30,-1,30,-9,-1,-9]
 x:12 y:12.5 imagbox:[-1,-1,30,-1,30,-9,-1,-9]
 x:12 y:12.5 imagbox:[-1,-1,30,-1,30,-9,-1,-9]
 x:12 y:12.5 imagbox:[-1,-1,30,-1,30,-9,-1,-9]
 x:12 y:12.5 imagbox:[-1,-1,30,-1,30,-9,-1,-9]
 x:12 y:12.5 imagbox:[-1,-1,30,-1,30,-9,-1,-9]
 x:33554459 y:12.5 imagbox:[-1,-1,-33554433,-1,-33554433,-9,33554430,-9]
 x:12 y:12.5 imagbox:[-1,-1,30,-1,30,-9,-1,-9]

So the problem is located on imagettfbbox funtion, it give wrong value for x position.
 [2010-03-19 16:36 UTC] administrateur at exinsidephp dot com
-Summary: imagettftext randomly don't work +Summary: imagettfbbox randomly don't work
 [2010-03-19 16:36 UTC] administrateur at exinsidephp dot com
rechange title
 [2010-03-23 14:52 UTC] administrateur at exinsidephp dot com
So I have find the origin of the problem : "GCC".

This problem appear if you compile PHP 5.3.2 width GCC 4.3.2 on Debian 32 bits. For fix the problem you must compile PHP 5.3.2 width GCC 4.1.2.
 [2010-03-23 15:04 UTC] pajoye@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: geissert
 [2010-03-23 15:04 UTC] pajoye@php.net
Raphael, can you take a look at this one please?
 [2010-03-23 20:59 UTC] geissert@php.net
Strange that you mention that it works with gcc 4.1.2. Last I heard 5.3.x failed to build with that version (don't know what arch was that, though).

Will take a look at it later. FWIW, a test related to imagettfbbox is reproducibly failing (with the same results on all archs):

ext/gd/tests/bug48801.log:
---- EXPECTED OUTPUT
(-1, 15)
(155, 15)
(155, -48)
(-1, -48)
---- ACTUAL OUTPUT
(1, 15)
(163, 15)
(163, -48)
(1, -48)
---- FAILED

And that was with 4.4.3 (same results without optimisation). Has anyone tried to reproduce it with the same or similar versions of gcc from another distribution?
 [2010-05-01 17:29 UTC] geissert@php.net
I tried with the following versions and with all of them the result is the same:
4.1.2, 4.2.4, 4.3.4, 4.4.3

So it's a bug on libgd's side. Will ask Sean as he is the maintainer at Debian.
 [2010-07-17 20:50 UTC] geissert@php.net
-Assigned To: geissert +Assigned To: pajoye
 [2010-07-17 20:50 UTC] geissert@php.net
According to Sean, this appears to be a bug in libgd that has been fixed in the 
copy included by PHP but not at upstream. I'm afraid I don't know any other 
detail.
Pierre, could you please take a look at it? (and if possible, update libgd 
upstream :)
 [2010-08-03 09:46 UTC] administrateur at exinsidephp dot com
I have upgrade my server for install DotDeb package with PHP 5.3.3 (apt-get update && apt-get ugrade) and the problem have disapear with this release.
 [2010-11-03 12:43 UTC] natan dot frei at gmail dot com
Debian Lenny
Linux v101.domain 2.6.26-2-openvz-686 #1 SMP Thu Sep 16 22:16:19 UTC 2010 i686 GNU/Linux
# dpkg -l | grep php
ii  libapache2-mod-php5             5.2.6.dfsg.1-1+lenny9    server-side, HTML-embedded scripting languag
ii  php-pear                        5.2.6.dfsg.1-1+lenny9    PEAR - PHP Extension and Application Reposit
ii  php5                            5.2.6.dfsg.1-1+lenny9    server-side, HTML-embedded scripting languag
ii  php5-cli                        5.2.6.dfsg.1-1+lenny9    command-line interpreter for the php5 script
ii  php5-common                     5.2.6.dfsg.1-1+lenny9    Common files for packages built from the php
ii  php5-curl                       5.2.6.dfsg.1-1+lenny9    CURL module for php5
ii  php5-gd                         5.2.6.dfsg.1-1+lenny9    GD module for php5
ii  php5-suhosin                    0.9.27-1                 advanced protection module for php5

The same issue.
Sometimes imagettfbbox returns wrong value for x position.
For example:
-1,0,-2147483648,0,-2147483648,-12,-1,-12
 [2010-11-03 12:47 UTC] pajoye@php.net
@natan dot frei at gmail dot com

Please try using the bundled GD instead, in the meantime.
 [2010-11-22 18:47 UTC] ken at smallboxcms dot com
I had this problem with the bundled version of GD in PHP 5.3.3. I am pretty much stuck at 5.2.9 as that was the last version of PHP where this bug did not happen.
 [2016-03-31 11:40 UTC] mplomer at gmx dot de
For proposed fix and further info/discussion, see bug #53504

This problem maybe should also be fixed by this patch (your example image URLs are not longer valid).
 [2016-09-23 14:37 UTC] cmb@php.net
-Status: Assigned +Status: Feedback -Assigned To: pajoye +Assigned To: cmb
 [2016-09-23 14:37 UTC] cmb@php.net
Please try with a current PHP snapshot and the bundled GD.
 [2016-10-02 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Jan 17 06:01:43 2017 UTC