Page 1 of 1

Wordwrap with GD

Posted: Sat Jul 28, 2007 12:05 am
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?

Posted: Sat Jul 28, 2007 6:20 am
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.

Posted: Sat Jul 28, 2007 3:08 pm
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.

Posted: Sat Jul 28, 2007 7:05 pm
by Ollie Saunders
Somewhat confusing but does the job: imagettfbox()

Posted: Sun Jul 29, 2007 6:38 pm
by Todd_Z
Yea, that's what im implementing.