Php - drawing text on an image within a box

Soldato
Joined
4 Jul 2004
Posts
2,647
Location
aberdeen
Hi,
I am trying to get php to draw some text on an image, within a certain box (so it wraps lines and doesn't "overflow"). The only way i've been able to do it at the moment is just adding a string a line at a time (And pre splitting it into new lines, by guessing the line lengths).

I've found imagettfbbox which can work out how much area a string will take up, but it won't automatically draw text within a box. Anyone know of any functions to do this?

thanks
 
i'd use the php wordwrap function. something like this.....

Code:
$string = 'blah blah';
$newstring = wordwrap($string, 30, '\n');
//now create an array with each element being a line of text
$array = explode('\n', $newstring);
//loop through array and output each line using imagettftext.....
foreach($array as $value) {
    imagettftext.....
 
Back
Top Bottom