|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2016-03-31 11:32 UTC] mplomer at gmx dot de
[2016-04-03 10:58 UTC] mplomer at gmx dot de
[2016-04-03 15:46 UTC] pajoye@php.net
-Status: Open
+Status: Assigned
-Assigned To:
+Assigned To: Pajoye
[2016-09-23 12:50 UTC] cmb@php.net
-Status: Assigned
+Status: Closed
-Assigned To: Pajoye
+Assigned To: cmb
[2016-09-23 12:50 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 09:00:01 2025 UTC |
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.