|
Posted by J.O. Aho on 07/30/05 15:30
Bas Varkevisser wrote:
> Hi,
>
> I need to calculate the length of a string in pixels to see if a text
> exactly fits in a fixed-width table.
Use fixed fonts, then just take the width times the length of the string.
<?PHP
$fontwidth=9;
$pixels=$fontwidth*strlen($string);
?>
For variable sized fonts, then you need to count how many of each type of
characters you have in the string and then multiply that with the width of
that character and lastly add all the values together.
A problem you will get with your page, not everyone will want to use the
default font size, some may use 120%, some one else maybe 90% and a third
150%, which makes you r page to look like crap in the end, better allow a page
to adjust after the needs of the surfer.
//Aho
Navigation:
[Reply to this message]
|