There is a function in the GD library that measures text size; http://www.php.net/manual/en/function.imagettfbbox.php But it has an advantage you don't have, once it has places exactly the font it wants, the size it wants, directly into an image, it knows that the browser won't change the image. With the font inside an image, the browser won't substitute another font, or use a different size because the one you have specified in your font statement is not available on the users machine. Perhaps there is a way for JavaScript to send you a list of available fonts on the end users machine? Course the end user could have fonts you never heard of. I think this is one of those things (like hand grenades and horse shoes) where being close counts. ;-) Warren Vail -----Original Message----- From: Robby Russell [mailto:robby@xxxxxxxxxxxxxxx] Sent: Thursday, October 28, 2004 3:27 PM To: Jacob Friis Cc: php-general@xxxxxxxxxxxxx Subject: Re: Review: Function that measures the width of a text string in pixels. On Fri, 2004-10-29 at 00:11 +0200, Jacob Friis wrote: > I have created a function that will measure the width of a text string > in pixels. It works ok. > If you have optimizations, please let me know. > Thanks, > Jacob > > function txt_width ($txt) { > $width = 0; > $txt_len = strlen($txt); > for ($n = 1; $n <= $txt_len; $n++) { > switch (substr($txt, $n, 1)) { > case 'l'; > case '.'; > case ' '; > case '-'; > case 't'; > $width += 3; > break; > default : > $width += 8; > break; > } > } > return $width; > } > .and how do you plan to account for things such as, font sizes on all platforms, font types, etc? -- /*************************************** * Robby Russell | Owner.Developer.Geek * PLANET ARGON | www.planetargon.com * Portland, OR | robby@xxxxxxxxxxxxxxx * 503.351.4730 | blog.planetargon.com * PHP/PostgreSQL Hosting & Development * --- Now supporting PHP5 --- ****************************************/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php