Finding A Word's Length In Pixels 
August 23rd, 2007, 01:55 PM
| | | Finding A Word's Length In Pixels
Here's a toughie for me.
Using the GD library, I want to print a word or string as an image,
but with some constant amount of padding around it. The text is not
known beforehand. In other words, something like
________
| |
| flan |
|________|
I'm very new to GD, but offhand the only solution that comes to mind
is to create a very long general-purpose image, print the text at (x1,
0), measure the word there, destroy the image, then create a second
image with dimensions calculated from before. That seems rather
sloppy. Is there a better alternative? | 
August 23rd, 2007, 02:05 PM
| | | Re: Finding A Word's Length In Pixels william.oram@gmail.com wrote: Quote:
Here's a toughie for me.
>
Using the GD library, I want to print a word or string as an image,
but with some constant amount of padding around it. The text is not
known beforehand. In other words, something like
>
________
| |
| flan |
|________|
>
I'm very new to GD, but offhand the only solution that comes to mind
is to create a very long general-purpose image, print the text at (x1,
0), measure the word there, destroy the image, then create a second
image with dimensions calculated from before. That seems rather
sloppy. Is there a better alternative?
>
| Hi,
If you use freetype2 fonts, have a look at:
imageftbbox()
imagefontheight()
imagefontwidth()
That should do the trick.
Regards,
Erwin Moller | 
August 23rd, 2007, 02:05 PM
| | | Re: Finding A Word's Length In Pixels
<william.oram@gmail.comwrote in message
news:1187877060.316184.32650@x40g2000prg.googlegro ups.com... Quote:
Here's a toughie for me.
>
Using the GD library, I want to print a word or string as an image,
| Why? If this is destined for a web page the the text should be exactly that,
text. Quote:
but with some constant amount of padding around it. The text is not
known beforehand. In other words, something like
| Margin on the image, using CSS?
--
Richard. | 
August 23rd, 2007, 03:05 PM
| | | Re: Finding A Word's Length In Pixels
On Aug 23, 8:59 am, "rf" <r...@invalid.comwrote: Quote:
Why? If this is destined for a web page the the text should be exactly that,
text.
| I promise you, I have a reason that makes plaintext insufficient. It
seems rather hasty to question and fix my project when I haven't said
a word about it. | 
August 23rd, 2007, 03:05 PM
| | | Re: Finding A Word's Length In Pixels
On Aug 23, 8:58 am, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote: Quote:
william.o...@gmail.com wrote:> Quote:
Using the GD library, I want to print a word or string as an image,
but with some constant amount of padding around it. The text is not
known beforehand. In other words, something like
| > Quote:
________
| |
| flan |
|________|
| > Quote:
I'm very new to GD, but offhand the only solution that comes to mind
is to create a very long general-purpose image, print the text at (x1,
0), measure the word there, destroy the image, then create a second
image with dimensions calculated from before. That seems rather
sloppy. Is there a better alternative?
| >
Hi,
>
If you use freetype2 fonts, have a look at:
imageftbbox()
imagefontheight()
imagefontwidth()
>
That should do the trick.
>
Regards,
Erwin Moller
| Perfect. Thanks! | 
August 23rd, 2007, 03:15 PM
| | | Re: Finding A Word's Length In Pixels
rf wrote: Quote:
<william.oram@gmail.comwrote in message
news:1187877060.316184.32650@x40g2000prg.googlegro ups.com... Quote:
>Here's a toughie for me.
>>
>Using the GD library, I want to print a word or string as an image,
| >
Why? If this is destined for a web page the the text should be exactly that,
text.
> Quote:
>but with some constant amount of padding around it. The text is not
>known beforehand. In other words, something like
| >
Margin on the image, using CSS?
>
| Possibly a CAPTCHA implementation?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex@attglobal.net
================== | 
August 23rd, 2007, 07:05 PM
| | | Re: Finding A Word's Length In Pixels
In article <qpgzi.25235$4A1.10019@news-server.bigpond.net.au>,
rf <rf@invalid.comwrote: Quote:
>
><william.oram@gmail.comwrote in message
>news:1187877060.316184.32650@x40g2000prg.googlegr oups.com... Quote:
>Here's a toughie for me.
>>
>Using the GD library, I want to print a word or string as an image,
| >
>Why? If this is destined for a web page the the text should be exactly that,
>text.
| Wrong. Don't make rash assumptions about what the project
requirements should be when that project hasn't been described. A
need was posted, so the proper response is to address that need
rather than question it. There are plenty of reasons why someone
may want to render text as graphics:
* Graphical display of data requires text on the graph axes and
legend, and that makes most sense as part of the graphic.
* CAPTCHA requires the use of text in graphics.
* Using some text as graphics is a good way to shield content from
spiders and crawlers.
* Clickable buttons containing text descriptions.
* Etc.
-A | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,989 network members.
|