Same function as above but it can display multi-line strings.
<?php
function sendimagetext($text) {
$font_size = 4;
$ts=explode("\n",$text);
$width=0;
foreach ($ts as $k=>$string) { $width=max($width,strlen($string));
}
$width = imagefontwidth($font_size)*$width;
$height = imagefontheight($font_size)*count($ts);
$el=imagefontheight($font_size);
$em=imagefontwidth($font_size);
$img = imagecreatetruecolor($width,$height);
$bg = imagecolorallocate($img, 0xAA, 0x00, 0x00);
imagefilledrectangle($img, 0, 0,$width ,$height , $bg);
$color = imagecolorallocate($img, 255, 255, 255);
foreach ($ts as $k=>$string) {
$len = strlen($string);
$ypos = 0;
for($i=0;$i<$len;$i++){
$xpos = $i * $em;
$ypos = $k * $el;
imagechar($img, $font_size, $xpos, $ypos, $string, $color);
$string = substr($string, 1);
}
}
header("Content-Type: image/png");
imagepng($img);
imagedestroy($img);
}
?>