By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,292 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

TTF text bounding box problem (imagettftext)

P: n/a
ljb
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
# 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);

header("Content-type: image/png");
imagepng($g);
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.