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
Re: Using imagettfbbox with Arial Bold [message #173253 is a reply to message #173252] Thu, 31 March 2011 07:16 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 31/03/2011 6:26, jwcarlton escribió/wrote:
> 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); }

If this is your real code, it should be throwing a couple of notices:
the $fontsize and $fontface variables are not defined inside the function.

>
> 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.

Are you using a <font> tag as reference?

The way TTF fonts get rendered is not unique and universal. It depends
on the renderer and its settings. What GD2 can tell you (and should be
telling you) is the size of the font as rendered by GD2 in that
computer. If you want to establish a correct comparison you need to
actually draw the font from PHP and grab a screenshot.



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[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: Fri Sep 20 17:43:34 GMT 2024

Total time taken to generate the page: 0.05584 seconds