php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49600 imageTTFText text shifted right
Submitted: 2009-09-19 15:47 UTC Modified: 2010-02-03 19:38 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: ch+php at 1111-internet dot com Assigned: tabe (profile)
Status: Closed Package: GD related
PHP Version: 5.2.11 OS: FreeBSD 7.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ch+php at 1111-internet dot com
New email:
PHP Version: OS:

 

 [2009-09-19 15:47 UTC] ch+php at 1111-internet dot com
Description:
------------
imageTTFText appears to have an issue with horizontal positioning of characters. This was introduced with 5.2.10 (which also had a vertical positioning issue cited in Bug #48801) and continues with 5.2.11 (where the vertical issue appears to have been corrected).

Nothing special in my config, but here it is just in case:

'./configure' '--prefix=/usr/local/php5' '--with-apxs2=/usr/local/apache2/bin/apxs' '--enable-track-vars' '--with-mysql=/usr/local/mysql' '--with-gd' '--with-zlib-dir=/usr/local' '--enable-zip' '--with-freetype-dir=/usr/local' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local' '--with-tiff-dir=/usr/local' '--with-mcrypt=/usr/local' '--with-pdflib=/usr/local' '--with-curl=/usr/local' '--enable-ftp' '--without-iconv' '--without-pear'


Reproduce code:
---------------
$image=imagecreatetruecolor(401, 51);
imagefill($image, 0, 0, imagecolorallocate($image, 255, 255, 255));
list($fontcolor, $outlinecolor, $gridcolor)=array(imagecolorallocate($image, 0, 0, 0), imagecolorallocatealpha($image, 255, 0, 0, 64), imagecolorallocate($image, 222, 255, 255));

for ($x=0; $x<=imagesx($image)-1; $x+=5) {imageline($image, $x, 0, $x, imagesy($image)-1, $gridcolor);}
for ($y=0; $y<=imagesy($image)-1; $y+=5) {imageline($image, 0, $y, imagesx($image)-1, $y, $gridcolor);}

foreach (array(array("face"=>"arial", "text"=>"E"), array("face"=>"arial", "text"=>"I"), array("face"=>"arial", "text"=>"P"), array("face"=>"arial", "text"=>"g"), array("face"=>"arial", "text"=>"i"), array("face"=>"arial", "text"=>"q"), array("face"=>"wingdng2", "text"=>"&#61630;"), array("face"=>"webdings", "text"=>"&#61476;")) as $index=>$array)
{
	list($xl, $yb, $xr, $yb2, $xr2, $yt)=imagettftext($image, 32, 0, 10+$index*50, 36, $fontcolor, "/www/fonts/". $array["face"]. ".ttf", $array["text"]);
	imagerectangle($image, $xl, $yt, $xr, $yb, $outlinecolor);
}

header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
exit;


Expected result:
----------------
characters should fit neatly inside the rectangle outlines drawn using the return values from imagettftext, and should left align to the $x parameter of imagettftext


Actual result:
--------------
http://www.1111-internet.com/images/php5_2_11_gdft_hpos.png

outline rectangles appear to be correct sizes and positions, but characters are often shifted right


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-19 17:34 UTC] ch+php at 1111-internet dot com
Here's the correct result produced by the same code example with 5.2.9:

http://www.1111-internet.com/images/php5_2_9_gdft_hpos.png
 [2009-09-19 17:49 UTC] pajoye@php.net
Tabe, can you take a look at this bug please? The only change in this area was the latest patch about bbox.
 [2009-09-25 05:00 UTC] ch+php at 1111-internet dot com
Just noticed that the text positioning between the two examples is exactly the same - it's the bounding coordinates that changed. This suggests that in <=5.2.9 BOTH the text and the boxes were shifted right (which was less noticeable in practice since they were in sync - but a closer inspection of the 5.2.9 example does show this). The bounding coordinates are now where one would expect them to be, but that's not where the text is.
 [2010-01-08 12:18 UTC] svn@php.net
Automatic comment from SVN on behalf of tabe
Revision: http://svn.php.net/viewvc/?view=revision&revision=293268
Log: Bug #49600 (imageTTFText text shifted right)
- fix difference of horizontal position between imagettftext() and imagettfbbox()
 [2010-02-03 17:41 UTC] svn@php.net
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=294423
Log: - Merge #49600 (imageTTFText text shifted right)
 [2010-08-05 16:44 UTC] barts at hexon dot cx
The fix for this bug was reverted in revision 296693, which fixed bug #51263. Re-applying the patch for this bug will break the alignment of angled text, so another solution is required.

Test script:
<?php
$expected = imagettfbbox(24, 0, 'courier', 'Foobar');

$img = imagecreatetruecolor(100, 100);
$color = imagecolorallocate($img, 0, 0, 0);

$actual = imagettftext($img, 24, 0, 0, 0, $color, 'courier', 'Foobar');

var_dump($expected);
var_dump($actual);
?>

Expected:
$expected equals $actual

Actual result:
array(8) {
  [0]=>
  int(-1)
  [1]=>
  int(-1)
  [2]=>
  int(108)
  [3]=>
  int(-1)
  [4]=>
  int(108)
  [5]=>
  int(-21)
  [6]=>
  int(-1)
  [7]=>
  int(-21)
}
array(8) {
  [0]=>
  int(0)
  [1]=>
  int(0)
  [2]=>
  int(109)
  [3]=>
  int(0)
  [4]=>
  int(109)
  [5]=>
  int(-20)
  [6]=>
  int(0)
  [7]=>
  int(-20)
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC