Jump to content

GD to wrap text in image?


hp1

Recommended Posts

Hi all,I'm using GD to create images with 'quotes' in them. At the moment I am storing the quotes in an array but eventually I will probably store them in an external file so I can call them randomly. Before that I have a problem I need to solve. I fthe quote is wider than the image box then it just gets cut off. How do I tell it to wrap the text inside the boundary of the Image? Many Thanks

<?phpheader("Content-type: image/png");$image = imagecreate( 200, 200);$pass['test1']="this is a test";$pass['test2']="This is a test2";$text=ImageColorAllocate($image, 200, 100, 100);$fill=ImageColorAllocate($image, 0, 0, 0);ImageFill($image, 0, 0, $fill); ImageString($image, 3, 30, 3, $pass['test2'], $text);imagepng($image);imagedestroy($image);?>

Link to comment
Share on other sites

OK i've now discovered the wordwrap function in php. Great, except where I have told it to break for a new line with a "\n" its inserting a funny symbol that looks like a small 'v' above a small 't' insetad of breaking for a new line. Is this something to do with the font perhaps?

$newtext=wordwrap($pass['test2'], 20,"\n");

and then

ImageString($image, 5, 5, 3, $newtext, $textcolor);

cheers

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...