php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50971 imagettftext/imagettfbbox return wrong coordinates if angle != 0
Submitted: 2010-02-09 06:39 UTC Modified: 2016-09-23 13:03 UTC
Votes:4
Avg. Score:3.8 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:1 (25.0%)
From: sks76543210 at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: GD related
PHP Version: 5.*, 6 OS: CentOS 5
Private report: No CVE-ID: None
 [2010-02-09 06:39 UTC] sks76543210 at gmail dot com
Description:
------------
imagettftext() and imagettfbbox() both return wrong bounding box if the angle is not set to 0. This sounds similar to a bug closed last year at http://bugs.php.net/bug.php?id=43073

See http://www.yessum.org/gdbug2/ for font and samples. This bug appears to be in 5.1.6, and has since gotten worse in the latest svn. 

Also, in 5.3.3-dev, the text doesn't seem to even be on the same baseline on many of the angles.

Reproduce code:
---------------
<?php
    $font = './cour.ttf'; // Courier New
    
    $im = imagecreatetruecolor(600, 600);
    
    imagefill($im, 0, 0, imagecolorallocate($im, 224, 224, 224));
    $black = imagecolorallocate($im, 0, 0, 0);
    $red = imagecolorallocate($im, 255, 0, 0);
    
    $angle = 0;
    do {
        $bbox = imagettftext($im, 16, $angle, 299, 299, $black, $font, 'The quick brown fox');
        imagepolygon($im, $bbox, 4, $red);
        $angle += 45;
    } while ($angle < 360);
    
    header('content-type: image/png');
    imagepng($im);

Expected result:
----------------
The bounding box should be a bounding box

Actual result:
--------------
The string is not contained in the bounding box.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-09 09:53 UTC] pajoye@php.net
Which GD library do you use? Bundled?
 [2010-02-09 13:04 UTC] sks76543210 at gmail dot com
The bug occurs in the two PHP versions I have available to test on here. Perhaps I can try on a win32 box when I get to work.

PHP 5.3.3-dev compiled from src
-------------------------------
GD Version: bundled (2.0.34 compatible)
Freetype Version: 2.2.1

./configure  --with-apxs2=/home/user/bin/httpd/bin/apxs --prefix=/home/user/bin/php --with-pdo-mysql --with-zlib --with-gd --with-gettext --with-freetype-dir --enable-gd-native-ttf



PHP 5.1.6 from centos rpms
--------------------------
GD Version: bundled (2.0.28 compatible) 
FreeType Version 2.2.1
 [2010-02-12 22:35 UTC] jvp at 4ssl dot us
*****     failures from 'make test' of 5.2.12     *****
these types of problems keep recurring (since 2001) so it seems that svn changes sometimes never make it to a stable release or there is no co-ordination with gd developers to prevent them from popping up again.

i am normally happy with the centos lag away from fresh releases, but i need at least 5.2.12 for nginx and that is why i am trying to compile from source.

     1.) 'Bug #43073/#48732 (TrueType bounding box is wrong for angle<>0) [ext/gd/tests/bug43073.phpt]';
     2.) 'Bug #48801/#48732 (Problem with imagettfbbox) [ext/gd/tests/bug48801.phpt]'; also (maybe)
     3.) 'Test imagecolorallocate() function : usage variations  - passing different data types to fourth argument [ext/gd/tests/imagecolorallocate_variation4.phpt]'

using:
     Linux 2.6.18-128.1.1.el5.028stab062.3 
     #1 SMP MSD 2009 x86_64 x86_64 x86_64 GNU/Linux 
     2.0.33 of gd.x86_64, gd-devel.x86_64, & gd-progs.x86_64
     2.2.1 of freetype.x86_64 & freetype-devel.x86_64
     5.1.0 of t1lib.x86_64 & t1lib-devel.x86_64

     .\configure 	\
	--disable-cgi	\
	--disable-ipv6    	\
	--enable-bcmath    	\
	--enable-calendar   	\
	--enable-dom    	\
	--enable-exif    	\
	--enable-fastcgi  	\
	--enable-force-cgi-redirect 	\
	--enable-ftp    	\
	--enable-gd-jis-conv   	\
	--enable-gd-native-ttf   	\
	--enable-json   	\
	--enable-pdo 	\
	--enable-short-tags    	\
	--enable-soap   	\
	--enable-sockets    	\
	--enable-zip   	\
	--with-Xpm-dir   	\
	--with-apxs2=\usr\sbin\apxs 	\
	--with-bz2   	\
	--with-curl   	\
	--with-db4   	\
	--with-freetype-dir 	\
	--with-gd   	\
	--with-gettext   	\
	--with-imap   	\
	--with-imap-ssl   	\
	--with-jpeg-dir 	\
	--with-kerberos 	\
	--with-libdir=lib64  	\
	--with-mcrypt   	\
	--with-mhash   	\
	--with-mysql  	\
	--with-mysql-sock  	\
	--with-mysqli 	\
	--with-ncurses  	\
	--with-pdo-mysql  	\
	--with-png-dir 	\
	--with-pspell  	\
	--with-snmp  	\
	--with-t1lib   	\
	--with-ttf   	\
	--with-xpm-dir 	\
	--with-xsl 	\
	--with-zlib-dir
--
thank you,

johann
 [2010-02-12 23:38 UTC] pajoye@php.net
Tabe, can you look at this one too? I get the feeling that it is fixed already, by your last commit there.
 [2010-05-25 21:25 UTC] sidhe at rocketmail dot com
Bug #51263 is reported for PHP 5.3.*, but is also an issue for 5.2.13, and appears to be related to this issue.
 [2013-04-06 11:17 UTC] fredcm at gmail dot com
In PHP 5.3.23 I found the same problem. The X coordinate of the function 
imagettfbbox always return -1.
 [2016-03-31 11:42 UTC] mplomer at gmx dot de
For proposed fix and further info/discussion, see bug #53504
 [2016-09-23 12:55 UTC] cmb@php.net
-Status: Assigned +Status: Closed -Assigned To: tabe +Assigned To: cmb
 [2016-09-23 13:03 UTC] cmb@php.net
-Status: Closed +Status: Duplicate
 [2016-09-23 13:03 UTC] cmb@php.net
Actually, this is a duplicate of bug #53504.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 22:01:26 2024 UTC