php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27410 TTF Font positioning Unstable Across Fonts at Zero Degrees
Submitted: 2004-02-26 21:00 UTC Modified: 2004-02-27 02:44 UTC
From: Gregory_mucha at hotmail dot com Assigned:
Status: Not a bug Package: GD related
PHP Version: 4.3.4 OS: Win98SE
Private report: No CVE-ID: None
 [2004-02-26 21:00 UTC] Gregory_mucha at hotmail dot com
Description:
------------
Application requires use of multiple truetype fonts to create a dynamic display of characters, varying font sizes and colors.

As the same font is varied by size, the starting position of the font appears to vary at zero degrees display.  This can be corrected with math when a single font is utilized, but the problem quickly gets out of hand when multiple fonts are used in the application.  The symptoms of cut-off appear the same for a given font, but across fonts the symptoms do vary.  Generally, two of the four sides of the bounding box appear to be too small and the (x,y) start position incorrect.

I have gone to Boutell and asked for help, but he claims that ImageTTFBBox and ImageTTFText are not his routines and the problem is not, therefore, GD-related.

HAAAAAAALPPPP!!!

Reproduce code:
---------------
Header("Content-type: image/png");
$xshift = 0;   // AACHENB @ 50
$yshift = 0;   //
$xpad   = 0;   //
$ypad   = 0;   // 
$benchmark = "Mgy_|jW";
$box1 = imagettfbbox_t($s, 0, $font, "o");
$box2 = imagettfbbox_t($s, 0, $font, "gyjp");
$baseline = ($box2[1] - $box2[7]) - ($box1[1] - $box1[7]);
$box = imagettfbbox_t($s, 0, $font, $text . $benchmark);
$height = ($box[1] - $box[7]) + $ypad;
$box = imagettfbbox_t($s, 0, $font, $text);
$width  = ($box[2] - $box[0]) + $xpad;
$im = imagecreate($width, $height);
$bgc = hex2dec($bg_color);
$bg = ImageColorAllocate($im, $bgc['r'], $bgc['g'], $bgc['b']);
$mac = hex2dec($text_color);
$main = ImageColorAllocate($im, $mac['r'], $mac['g'], $mac['b']);
ImageTTFText($im, $s, 0, $xshift, ($height - $baseline) + $yshift, $main, $font, $text);
ImagePng($im);
ImageDestroy($im);

Expected result:
----------------
http://www.geocities.com/paul475aw/Expected_Output.png

Actual result:
--------------
http://www.geocities.com/paul475aw/Actual_Output.png

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-27 02:44 UTC] sniper@php.net
imagettfbbox_t() does not exist in PHP. 

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 14:01:31 2024 UTC