Bug #65837 [Com]: imageTTFText text shifted right

From: Date: Thu, 31 Mar 2016 11:48:27 +0000
Subject: Bug #65837 [Com]: imageTTFText text shifted right
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200266@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65837&edit=1 ID: 65837 Comment by: mplomer at gmx dot de Reported by: c dot madmax at gmail dot com Summary: imageTTFText text shifted right Status: Assigned Type: Bug Package: GD related Operating System: Ubuntu 12.04 PHP Version: Irrelevant Assigned To: tabe Block user comment: N Private report: N New Comment: Drawing text is always based on the "origin"-point of a glyph ... there is a glyph-specific "left margin" (the bearingX) which is correct, to get an "optical" (not "physical"!) vertical baseline over multiple lines (see http://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html#section-3 - the graphic below). So the bug is not about the text is shifted right - but the bounding box is shifted left: For proposed fix and further info/discussion, see bug #53504 Previous Comments: ------------------------------------------------------------------------ [2013-10-05 10:39:42] c dot madmax at gmail dot com Description: ------------ Hello PHP Developers, I want to inform you about a imageTTFText() bug that exists since four years. The problem is that imageTTFText text is shifted right. The bug is only visible when using a large fontsize. The bigger the font the larger the shift. The bug was introduced with PHP 5.2.10 and reported here: http://bugs.php.net/bug.php?id=49600 As you can see in the history of bug 49600, a fix was made in revision 293268 and the bug was closed. But then the fix was reverted in revision 296693 and obviously no one has noticed that. I strongly urge you to fix this problem. I am using PHP 5.4.0 on Ubuntu 12.04. I am sure the bug still exists in all php versions >=5.2.10 until this day (except revision 293268-296693). I have made a test script and uploaded a sample image on two image hosters to illustrate how massive the shift is: http://img407.imageshack.us/img407/1888/mbxe.png (best quality) http://img223.imagevenue.com/img.php?image=61219_imagettftext_shifted_122_1017lo.jpg As you can see on the image, the character 'C' is NOT left aligned as it should because the x position is zero. The character is shifted approximately 20 pixels instead and overlap the polygon (which is properly left-aligned). Some characters like 'A' or 'V' are only a little bit shifted, but also overlap the polygon. It does not matter what font you use, all are right shifted. Note: The array that is returned from imagettfbbox produces values that differ 1 pixel from the values returned from imageTTFText (when using x=0; y=0) which is also a bug. Please use my test script and verify the problem. If a php developper whould use this test script each time he made a change in imageTTFText, then such bugs would not occour. It seems the developer do not have enough carefulness. That's a point you should think about. Test script: --------------- <?php $im = imagecreatetruecolor(500, 500); $bgcolor = imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255)); $fgcolor = imagecolorallocatealpha($im, 0, 0, 255, 64); imagefill($im, 0, 0, $bgcolor); $polygon = imagettftext( $im, 480, // size 0, // angle 0, // x 480, // y $fgcolor, '/usr/share/fonts/truetype/msttcorefonts/verdana.ttf', 'C' // text ); imagesetthickness($im, 2); imagepolygon( $im, $polygon, sizeof($polygon) / 2, imagecolorallocatealpha($im, 255, 0, 0, 64) ); header('Content-Type: image/png'); imagepng($im); exit; ?> Expected result: ---------------- The polygon should enclose the character 'C' without overlapping the character. Actual result: -------------- The polygon overlap the character 'C' because every character is shifted right. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65837&edit=1

« previous php.bugs (#200266) next »