Re: Review: Function that measures the width of a text string in pixels.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
}
the width depends on the font used (monospace or not), the kerning used, the size of whitespaces, etc. you can't say "the width of X will be Y" without knowing the font, font size, kerning, etc.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux