You should need to use GD libraries. (comes with the latest PHP versions)
Something like:
<?php
function randomText() {
// Your random text function ..
return $randomText;
}
header("Content-type: image/jpeg");
$im = imagecreate(400,30);
$white = imagecolorallocate($im, 255,255,255);
$black = imagecolorallocate($im, 0,0,0);
imagettftext($im, 20, 0, 10, 20, $black, "/path/arial.ttf",
randomText());
imagejpeg($im);
imagedestroy($im);
?>