Review: Function that measures the width of a text string in pixels.
| From: | Jacob Friis | Date: | Thu, 28 Oct 2004 22:11:24 +0000 |
| Subject: | Review: Function that measures the width of a text string in pixels. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-200585@lists.php.net to get a copy of this message | ||
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;
}