Wrap lines of text within image boundaries using gd

Viewed 4032

I am trying to write text from a db to images. The text some times contains lengthy lines so that it does't fit in one line on image.

As of now I am getting the output as: http://prntscr.com/29l582

This is the code for this:

$imageCreator = imagecreatefrompng($i+1 . ".png");
        $textColor = imagecolorallocate($imageCreator, 0, 0, 0);
        $textfromdb = $factformatted['fact'];
        $y = imagesy($imageCreator) - 228;
        $dimensions = imagettfbbox(20, 0, $fontname, $textfromdb);
        $x = ceil(($imageWidth - $dimensions[4]) / 2);
        imagettftext($imageCreator, 20, 0, $x, $y, $textColor, $fontname, $textfromdb);
        imagepng($imageCreator, "./fact".$i.".png");

Can someone help me to make it work?

1 Answers
Related