Do you have a question? Post it now! No Registration Necessary. Now with pictures!
May 3, 2005, 6:14 am
rate this thread
Using PHP-4.3.11 with GD extension, bundled GD library, and freetype-2.1.9
(with X.org 6.8.1). I can't get the TrueType Font (TTF) bounding box to
come out right. Whether using imagettftext() or imagettfbbox(), for some
angles of text (like 45 degrees), the box comes back in the wrong place.
Sample code below; just change the $font assignment to point to a TTF font
file. You should see a text string with a box around it, but my box isn't
always around the text, depending on the $angle.
Could someone please sanity check this before I open a bug report?
# PHP GD TTF Bounding Box Test
# Change this to the full path of a TrueType font you have:
$font = '/usr/local/lib/fonts/truetype/arial.ttf';
$size = 36.0;
$angle = 135.0; # Try 45, 135, 260 degrees for example
$g = imagecreate(800, 600);
$white = imagecolorallocate($g, 255, 255, 255);
$black = imagecolorallocate($g, 0, 0, 0);
# Draw the text string:
$bbox = imagettftext($g, $size, $angle, 400, 300, $black, $font, 'ABCDEF');
# Draw the bounding box:
imagepolygon($g, $bbox, 4, $black);
- » PHP to email (with optional attachements) expert required
- — Previous thread in » PHP Scripting Forum
- » ssh on command line: force using a group size (prime size) of 1024 (and no...
- — The site's Newest Thread. Posted in » Secure Shell Forum