.8)); $text_width = ($sizeArray[4] - $sizeArray[0]); // define word separators to have a new line entry // if this line fits, we need to see if another word will fit on this line if($text_width < $width) { // add next word to the line with a space $sizeArray2 = imageFTBBox($size, 0, "fonts/$font", $final_text." ".$word_array[$i], array("linespacing" => .8)); $text_width2 = ($sizeArray2[4] - $sizeArray2[0]); if($text_width2 < $width) { // if text will fit, add a space between words $separator = " "; } else { // if text is too long, add a new line character $separator = "\r\n"; } } else { // add new line character if original measurement was more than 100px $separator = "\r\n"; } // build the text so far $final_text = $final_text.$separator.$word_array[$i]; } // create the base image $img_handle = ImageCreate($width, $height) or die ("Cannot Create Image"); // set a background color $background = ImageColorAllocate($img_handle, 255, 255, 255); // make that background color transparent ImageColorTransparent($img_handle, $background); // set text color $txt_color = ImageColorAllocate($img_handle, 1, 1, 1); // render text ImageFTText($img_handle, $size, 0, 00, 7, -10, "fonts/$font", $final_text, array("linespacing" => .8)); // create the PNG image // since we're not saving the image - we don't define a file name // if we wanted to save the image, a file name would appear after the $img_handle ImagePNG ($img_handle); // destroy the image to free server memory ImageDestroy($img_handle); ?>