Write text to PHP generated PNG

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Write text to PHP generated PNG

Post 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!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

imagettfbbox() will be useful here too.
Post Reply