php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51207 imageTTFText: misalignment of characters which extend beyond their left margin
Submitted: 2010-03-05 01:28 UTC Modified: 2010-06-22 00:56 UTC
Votes:10
Avg. Score:5.0 ± 0.0
Reproduced:9 of 9 (100.0%)
Same Version:8 (88.9%)
Same OS:5 (55.6%)
From: penkert at yahoo dot com Assigned: pajoye (profile)
Status: Closed Package: GD related
PHP Version: 5.2.13 OS: Linux & Windows XP
Private report: No CVE-ID: None
 [2010-03-05 01:28 UTC] penkert at yahoo dot com
Description:
------------
The following bug is present in PHP 5.2.13 and was not present in PHP 5.2.11. (It was probably introduced while attempting to solve Bug #49600.) My test bed is Windows XP/Apache 2.0, production site runs on Linux/Apache 1.3, both are showing the same symptom.

We are using the commercial font "Pirouette Text" by Linotype which I obviously cannot include in this report. What sets this font apart from most other fonts is the fact that some characters extend horizontally beyond their bounding boxes in terms of character placement.

My little test script spells out the word "Information" in "Pirouette Text". In this font the letter "f" (among others) is made up of a large S-like curve extending well into its neighboring letters

Test script:
---------------
$text = "Information";
$font = "pirouette.otf";
$size = 41;

$dim = imagettfbbox($size, 0, $font, $text);
$off_y = -$dim[7];
$off_x = -$dim[0];
$img_h = $dim[1]+$off_y+1;
$img_w = $dim[2]+$off_x+2;
unset($dim);

$img = imagecreatetruecolor($img_w, $img_h);
imagefilledrectangle($img, 0, 0, $img_w-1, $img_h-1, 0xFFFFFF);
imagettftext($img, $size, 0, $off_x, $off_y, 0x000000, $font, $text);
header("Content-Type: image/gif");
imagetruecolortopalette($img, false, 32);
imagegif($img);
imagedestroy($img);

Expected result:
----------------
This is what it should look like (rendered by PHP 5.2.11):
http://mitglieder.hrc1880.de/penkert/php5_2_11.gif

Actual result:
--------------
And this is how PHP 5.2.13 messes it up:
http://mitglieder.hrc1880.de/penkert/php5_2_13.gif

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-05 02:34 UTC] penkert at yahoo dot com
Sorry, I forgot to mention I'm talking about PHP's imageTTFText function.

And also, while previewing and editing my report the part of my last paragraph after the apostrophe got lost. So here it is again:

My little test script spells out the word "Information" in "Pirouette Text". In this font the letter "f" (among others) is made up of a large S-like curve extending well into its neighboring letters' "territories". PHP 5.2.11 places the "f" correctly. PHP 5.2.13, on the other hand, seems to use the character's leftmost extremum for positioning it next to the previous character which is, of course, incorrect. There are a few more minor differences between the two PHP version's results----all in favor of 5.2.11.
 [2010-03-06 18:54 UTC] sks76543210 at gmail dot com
Looks like a duplicate of bug #50194 and bug #50958
 [2010-03-06 19:44 UTC] penkert at yahoo dot com
I had a look at those two bugs before writing up my report. In fact, their seem to be quite a number of similar bugs concerning imageTTFText. But the thing is that the bug I'm describing was not present in PHP 5.2.11. So, even though all of these bugs are probably related in some way or other I decided they can't actually be one and the same.
 [2010-03-06 20:07 UTC] penkert at yahoo dot com
BTW, about my Win32 testbed:

PHP 5.2.11, GD bundled (2.0.34 compatible), FreeType 2.1.9 => OK

PHP 5.2.13, GD bundled (2.0.34 compatible), FreeType 2.1.9 => buggy result


Debian production system:

PHP 5.2.13, GD bundled (2.0.34 compatible), FreeType 2.2.1 => buggy result

(can't go back to older PHP version there)
 [2010-03-11 15:21 UTC] dbrow75 at yahoo dot com
I too am seeing issues since my HOST upgraded to PHP 5.2.13.  We use a Monogram font to create and image and the center character is now mis-aligned as well circle that should be surrounding all the character is missing.

http://tools.sorellajewelry.com/text_to_png.php?font=7&text=aAa

You can see the middle character is shifted right and the outer circle is missing.

I have on running on a PHP  5.2.6 dev system with no issues.
 [2010-03-11 15:29 UTC] dbrow75 at yahoo dot com
Example of broken image and correct image, same underlying code only difference is PHP version (and GD library FreeType which got upgraded in PHP upgrade)

http://tools.sorellajewelry.com/broken.png     (5.2.13, FreeType 2.1.9)

http://tools.sorellajewelry.com/Correct.png     (5.2.9, FreeType 2.2.1)
 [2010-03-11 15:51 UTC] dbrow75 at yahoo dot com
sorry flipped flopped FreeType versions, should be

http://tools.sorellajewelry.com/broken.png     (5.2.13, FreeType 2.2.1)

http://tools.sorellajewelry.com/Correct.png     (5.2.9, FreeType 2.1.9)
 [2010-03-12 16:24 UTC] penkert at yahoo dot com
Any chance you could provide the font you're using to the PHP team? We're using the commercial font Pirouette Text by Linotype which I obviously can't just hand out freely. Of course, this makes it very difficult for a third party to reproduce my bug. Hence, another reproducibly bug scenario would probably be immensely helpful...
 [2010-03-12 22:18 UTC] dbrow75 at yahoo dot com
Hi,

both paid fonts as well.

HMSNMW__.TTF (HM Snowflake MonogramsWhite)and vinemsb_.ttf (Vine Monograms Solid Bold) were both affected.  

Both are from Harold's Fonts which can be found at http://www.fontbros.com/cgi-bin/commerce.cgi?search=action&category=1210
 [2010-03-15 10:54 UTC] kakketaf at hotmail dot com
Same problem here with the font Francisco lucas liana (http://www.dafont.com/francisco-lucas.font).
Problem occurred when webhost upgraded to 5.2.13.

I'm using imageTTFText to create dynamic headings for news items. This got pretty messy :-(
 [2010-03-29 05:10 UTC] penkert at yahoo dot com
How can I make sure the font I'm using (Linotype Pirouette Text) is 100% standards compliant? Since it's a commercial font I always assumed it's all right, but I guess you never know. I can only say it's been working flawlessly in any other program I used so far.

I'm asking this question because I just did a little more testing and ran the above script with different fragments of the word "Information" (and a different background color). I was surprised to find that PHP 5.2.11 isn't handling the font perfectly either. (I just never noticed this before for lack of problematic words.) Here are the results of my testing:

PHP 5.2.13 "Information":
http://mitglieder.hrc1880.de/penkert/php5_2_13_information.gif

PHP 5.2.13 "Inf":
http://mitglieder.hrc1880.de/penkert/php5_2_13_inf.gif

PHP 5.2.13 "formation":
http://mitglieder.hrc1880.de/penkert/php5_2_13_formation.gif

PHP 5.2.13 "f":
http://mitglieder.hrc1880.de/penkert/php5_2_13_f.gif

(I'll have to put the result links for PHP 5.2.11 in a different post due to your spam protection being a little bit too picky...)

As you can see in my script, the generated image is automatically sized by the output of the imageTTFBox function. In all of these cases the calculated dimensions are exactly what they should be. However, positing in imageTTFBox isn't working correctly either----with varying results between the two PHP versions.

Is there anything else I can do to help?
 [2010-03-29 05:11 UTC] penkert at yahoo dot com
As promised, here're the results for PHP 5.2.11.

PHP 5.2.11 "Information":
http://mitglieder.hrc1880.de/penkert/php5_2_11_information.gif

PHP 5.2.11 "Inf":
http://mitglieder.hrc1880.de/penkert/php5_2_11_inf.gif

PHP 5.2.11 "formation":
http://mitglieder.hrc1880.de/penkert/php5_2_11_formation.gif

PHP 5.2.11 "f":
http://mitglieder.hrc1880.de/penkert/php5_2_11_f.gif
 [2010-03-29 10:39 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2010-03-29 10:39 UTC] pajoye@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2010-03-29 17:25 UTC] penkert at yahoo dot com
-Status: Feedback +Status: Open
 [2010-03-29 17:25 UTC] penkert at yahoo dot com
It seems there are no snapshots for Windows available at this time but I'll be happy to check back later. (I need Windows binaries for my testbed.) Thanks for your help!
 [2010-04-08 09:59 UTC] helice at gmx dot net
The issue exists since php 5.2.13 and 5.3.2.

It is even worse when angle is other than 0.

For me there is high priority as I'm not the administrator of my webserver.
 [2010-04-08 10:09 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2010-04-08 10:09 UTC] pajoye@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2010-04-08 11:35 UTC] helice at gmx dot net
@pajoye

latest snap 5.3 works nearly fine for a 90° angle on os-x 10.6.3 with common fonts (arial, georgia, 1942) only the free ttf BabelSans outputs an odd angle of about 87°.

I hope it will be the same for 5.2(.14?) and very soon on my provider's server.

Many thanks
 [2010-04-08 11:39 UTC] pajoye@php.net
Not sure how to interpret your answer :) Did it fix the problem?
 [2010-04-08 13:15 UTC] helice at gmx dot net
Sory.

It'solves my actual issue on php 5.3.2.
But I only tested my current implementation (the extension texttoimage included in ezpublish) with an angle of 90°.
I checked the fonts arial (ttf source:os X), georgia (ttf:os X), 1942 (ttf:ez-publish package) and BabelSans (ttf:freefont). The first three worked ok. BabelSans wasn't outputed as expected at 90° but at about 87° (a part of the text disapears out of the image frame).

Conclusion: 
As it is, the patch would solve my urgent concerns which jeopardize my production site. Allas the exeption BabelSans seems to indicate that it still doesn't work in every case. 

Hope that helps
 [2010-04-08 13:18 UTC] pajoye@php.net
Is it a public font? Can you send it to me pls or attach it this bug report?
 [2010-04-08 14:01 UTC] helice at gmx dot net
I hope you find my email at your displayed address.
 [2010-04-08 14:08 UTC] penkert at yahoo dot com
I'd be more than happy to test new snapshots but there are still no Windows binaries available at http://windows.php.net/snapshots/
 [2010-06-21 22:54 UTC] clay dot bell at electricarrow dot com
The kerning in 5.3.2 is awful compared to 5.2.11. Both were compiled on linux with 
the same gd library and using the same true type font. I'm using the imagettftext 
method.

I'm forced to use 5.3.2 to be PCI compliant so I hope a fix is available.
 [2010-06-21 22:59 UTC] pajoye@php.net
clay dot bell at electricarrow dot com, see the comments, try 5.3.3RC1 please.
 [2010-06-21 23:58 UTC] clay dot bell at electricarrow dot com
Thanks, I've tested kerning PHP Version 5.3.3RC2-dev and it looks like its fixed, 
it matches my test with 5.2.11 (appears that it will be fixed in the next 
production release).
 [2010-06-22 00:56 UTC] pajoye@php.net
-Status: Feedback +Status: Closed -Assigned To: +Assigned To: pajoye
 [2010-06-22 00:56 UTC] pajoye@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 02 12:01:29 2024 UTC