Re: Pixel Length of text message
| From: | heinisch at creaction dot de | Date: | Mon, 29 Apr 2002 16:28:51 +0000 |
| Subject: | Re: Pixel Length of text message | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-95206@lists.php.net to get a copy of this message | ||
At 29.04.2002 10:17, you wrote:
In html/css you can set a font size in pixels -- in my experience this means a letter takes the same number of pixels, regardless of resolution. With php, can I use string length and font pixel size to determine the length of a given string on a screen? Does anyone know an algorithm for this that works for any/every font?The chance that this works, even if you would have an algorithm is nearly null, as you don´t know which fonts are installed on the client, nor which version they have. Also what if the user disables JavaScript, then your nice css-stuff will not work either. To have text output to a specified length, you have to make it using gd. Then you are able to make a picture, containig the text you want . From this, you know it´s dimensions. but don´t forget the alt= attribute for people who have "load graphics" set off, or are not able to see graphics. HTH Oliver