[thelist] setting the wrap width of rendered text usng php gd

David U. davidu at everydns.net
Sun Oct 13 20:11:00 CDT 2002


Dunstan Orchard wrote:
> Hi again,
>
> does anyone know how to limit the width of text when writing it to an
> image in php?
>
> I am writing text to an image 300px wide, so I want to wrap the text
> display at something like 280px - but I can't figure out how?
>
> See an example of my text not wrapping here:
>
> http://www.1976design.com/testarea/photo/image4.php
>
>
> My plan is to limit the text width, then work out the height of the
> text box using imagettfbbox() then create the image with the height
> set to accomodate the text...

That's essentially what you need to do but I think in a slightly different
order.

using:
http://www.php.net/manual/en/function.imagettfbbox.php

you could write a small loop to keep adjusting the break in the text until
the bounding box is just small enough to fit inside the image.

By the way, that font looks great at 7.9 -- real sharp and easy to read.

-davidu


>
>
> Any help gratefully received,
>
> thanks as always,
>
> - dunstan
>
> ---------------------------
> Dorset, England
> http://www.1976design.com/
> http://www.orchard.it/
> http://www.maccaws.org/





More information about the thelist mailing list