I’m using the following code to generate font images from text entered on a form. If line returns are entered, a new line is started, & displays well. But if the textarea box on the form does the wrapping, the text displays all on one line, and sticks out on either side of the rectangle background. Is there a way to split the text string up into it’s individual words, and generate those individually, and wrapped?
[code=php]<?php
// ######################################
// This was written by Michael Morgan of
// CodingTuts (http://www.codingtuts.com)
// ######################################
$imageWidth = 500;
$imageHeight = 360;
$textFont = $_POST[‘font_type’];
$textSize = 30;
$textString = $_POST[‘text_msg’];
header(“Content-type: image/png”);
// Create the image
$image = imagecreatetruecolor($imageWidth, $imageHeight);
// Create some colors
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
// Fill the background of our image
imagefilledrectangle($image, 0, 0, $imageWidth, $imageHeight, $white);
// Get box info
$box = imagettfbbox($textSize, 0, $textFont, $textString);
//Find out the width and height of the text box
$textW = $box[2] – $box[0];
$textH = $box[5] – $box[3];
// Calculate the positions
$positionLeft = ($imageWidth – $textW)/2;
$positionTop = (($imageHeight – $textH)/2);
// Add some text
imagettftext($image, $textSize, 0, $positionLeft, $positionTop, $black, $textFont, $textString);
// Output the image to the browser
imagepng($image);
imagedestroy($image);
?>