PHP: Write String to a Jpeg
October 27, 2008 – 10:44 amThis function will dynamically create a jpeg from the string you provide. It even handles multi-line strings.
function str_to_jpg($str, $file) { $lines = explode("\n", $str); $number_lines = count($lines); $image = imagecreate(1000, ($number_lines * 16)); $background = imagecolorallocate($image, 0, 0, 0); $text = imagecolorallocate($image, 255, 255, 255); $pos = 2; foreach($lines as $line) { imagestring($image, 4, 1, $pos, $line, $text); $pos += 16; } imagejpeg($image, $file); imagedestroy($image); }