Page 1 of 1

Write text to PHP generated PNG

Posted: Thu Dec 13, 2007 10:08 pm
by waradmin
I am looking to create a new forum signature that pulls quotes from a DB and displays them in a black background PNG image. That part is easy, however some quotes are longer than the image so I need the text to wrap. How do I make the text wrap so it does not go off the image? Do I need to just count characters and once X characters is reached add a <br /> or is there a better way to do this?

Thanks in advance!

Posted: Thu Dec 13, 2007 10:37 pm
by John Cartwright
I think your best bet is to estimate the approximate width (depending on font, font style, width, etc) and do the calculations yourself.

Posted: Thu Dec 13, 2007 11:10 pm
by alex.barylski
It looks like imagefontwidth() will return the information you need...

Although I'm not sure how accurate the result is, if your using a font that is variable width I would guess it returns the pixel width of "W" typically the widest character...

Likewise you could calculate the height of the image using the counter-part...

Posted: Fri Dec 14, 2007 8:05 am
by feyd
imagettfbbox() will be useful here too.