Reply to Re: Calculate length of string in pixels?

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация