Wordwrap with GD

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
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Wordwrap with GD

Post by Todd_Z »

I am wondering if anyone has solved this problem already:

I have a rectangle of specific width and height, and I would like to find the maximum font size to properly format (and center) a paragraph in this area [ using GD ]

Right now, my solution is only for one-line paragraphs because it will properly calculate the font size, but the additional lines of text will simply be left-aligned with the first line. Ugly.

Any ideas folks?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Sounds to me like you're abusing GD. :?

I believe that you can get the width of characters in CD, so you'll need to calculate how many words can fit on each line individually, separate them as such. and then center them line by line.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

I am trying to create an application which dynamically creates decent looking advertisements.

I suppose I have figured out a solution, similar to what superdezign suggested.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Somewhat confusing but does the job: imagettfbox()
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Yea, that's what im implementing.
Post Reply