FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Using imagettfbbox with Arial Bold
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Using imagettfbbox with Arial Bold [message #173252] Thu, 31 March 2011 04:26 Go to previous message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma:
Member
I'm using imagettfbbox() to find the width of a variable-driven text
object. Like this:

$variable = "Business";
$fontsize = "9";
$fontface = "arialbd.ttf";

function get_bbox($text) { return imagettfbbox($fontsize, 0,
$fontface, $text); }

function t_width($text) {
$box = get_bbox($text);
$width = $box[4] - $box[6];

return $width;
}

$text_width = t_width($variable);

If I use arial.ttf, this works perfect. But I'm trying to find the
width of Arial Bold, which I assume is arialbd.ttf. When I change
$fontface to "arialbd.tff", the width comes out shorter than it should
be (my test phrases are coming out with a width anywhere from 0 to 7px
shorter than they really are).

For example, <font face="Arial"><b>Business</b></font> actually
measures 52px, but the above is returning 49px.

This is on a Linux machine, with GD2 installed.

Any suggestions on why this font is calculating incorrectly? Is there
a different/better way to measure bold text?

TIA,

Jason
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Firefox PHP error report
Next Topic: OpenSSL support => disabled (install ext/openssl)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 08:43:01 GMT 2024

Total time taken to generate the page: 0.05242 seconds