Connecting Tech Pros Worldwide Help | Site Map

Finding A Word's Length In Pixels

william.oram@gmail.com
Guest
 
Posts: n/a
#1: Aug 23 '07
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?

Erwin Moller
Guest
 
Posts: n/a
#2: Aug 23 '07

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
rf
Guest
 
Posts: n/a
#3: Aug 23 '07

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.


william.oram@gmail.com
Guest
 
Posts: n/a
#4: Aug 23 '07

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.

william.oram@gmail.com
Guest
 
Posts: n/a
#5: Aug 23 '07

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:
Here's a toughie for me.
>
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!

Jerry Stuckle
Guest
 
Posts: n/a
#6: Aug 23 '07

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
==================
axlq
Guest
 
Posts: n/a
#7: Aug 23 '07

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
Closed Thread