From:             
Operating system: Windows 7
PHP version:      5.3.3
Package:          GD related
Bug Type:         Bug
Bug description:imagettfbbox gives incorrect values for bounding box

Description:
------------
imagettfbbox() function is unreliable. Tried at several different angles
(including 0) with several characters at the test script. The spacing
around some letters is wrong, seemingly random parts of letters are chopped
off, some have too much space etc. I have tested this with 4 or 5 different
TTF fonts at different sizes, and the results are the same.



I am trying to use this to calculate spacing between letters, and can't,
because of this function's behaviour. I am having to write my own php
function to accomplish the same thing, and cache the results due to the
poorer performance.



Script used in the example is 'Bauhaus 93', a font bundled with Windows,
but the behaviour is common to all fonts.

Test script:
---------------
<?php

  $strText = "EXAMPLE";

  $imgOutput = imagecreate(1640, 1640);

  $colWhite = imagecolorallocate($imgOutput, 255, 255, 255);

  $colBlack = imagecolorallocate($imgOutput, 0, 0, 0);

  $colRed = imagecolorallocate($imgOutput, 255, 0, 0);

  imagefilledrectangle($imgOutput, 0, 0, 1640, 1640, $colWhite);

  for ($angle = 0; $angle < 360; $angle += 30)

    for ($i = 0; $i < strlen($strText); $i++) {

      $intX = 820 + (200 + ($i * 90)) * cos(deg2rad($angle));

      $intY = 820 - (200 + ($i * 90)) * sin(deg2rad($angle));

      imagettftext($imgOutput, 70, $angle, $intX, $intY, $colBlack,
"./fonts/BAUHS93.TTF", $strText{$i});

      $arrBoundingBox = imagettfbbox(70, $angle, "./fonts/BAUHS93.TTF",
$strText{$i});

      imageline($imgOutput, $arrBoundingBox[0] + $intX, $arrBoundingBox[1]
+ $intY, $arrBoundingBox[2] + $intX, $arrBoundingBox[3] + $intY, $colRed);

      imageline($imgOutput, $arrBoundingBox[2] + $intX, $arrBoundingBox[3]
+ $intY, $arrBoundingBox[4] + $intX, $arrBoundingBox[5] + $intY, $colRed);

      imageline($imgOutput, $arrBoundingBox[4] + $intX, $arrBoundingBox[5]
+ $intY, $arrBoundingBox[6] + $intX, $arrBoundingBox[7] + $intY, $colRed);

      imageline($imgOutput, $arrBoundingBox[6] + $intX, $arrBoundingBox[7]
+ $intY, $arrBoundingBox[0] + $intX, $arrBoundingBox[1] + $intY, $colRed);

    }//for

  header('Content-type: image/png');

  imagepng($imgOutput);

Expected result:
----------------
An image with the word 'EXAMPLE' printed out in angles incrementing by 30
degrees, and with a red box around each letter marking the bounding box of
each character in turn.

Actual result:
--------------
The red boxes do not indicate the bounds of the character, but chop parts
off and leave big spaces in other places, seemingly unpredictably.

-- 
Edit bug report at http://bugs.php.net/bug.php?id=53504&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=53504&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=53504&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=53504&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=53504&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=53504&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=53504&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=53504&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=53504&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=53504&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=53504&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=53504&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=53504&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=53504&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=53504&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53504&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53504&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=53504&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=53504&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=53504&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=53504&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=53504&r=mysqlcfg

Reply via email to