Подобная функция используется на всяких досках для объявления для перевода телефона или email-а из текста в картинку.
function Txt2Png( $text)
{
$png2display = md5($text);
$filenameforpng = $_SERVER['DOCUMENT_ROOT']."/cache/". $png2display . ".png";
$filename = "http://".$_SERVER['SERVER_NAME']."/cache/". $png2display . ".png";
if (!file_exists($filenameforpng)) # we dont need to create file twice (md5)
{
# definitions
$font = $_SERVER['DOCUMENT_ROOT'] . "/fonts/open_sans_regular.ttf";
# create image / png
$fontsize = 20;
$textwerte = imagettfbbox($fontsize, 0, $font, $text);
$textwerte[2] += 8;
$textwerte[5] = abs($textwerte[5]);
$textwerte[5] += 4;
$image=imagecreate($textwerte[2], $textwerte[5]);
$farbe_body=imagecolorallocate($image,255,255,255);
$farbe_b = imagecolorallocate($image,0,0,0);
$textwerte[5] -= 2;
imagettftext ($image, $fontsize, 0, 3,$textwerte[5],$farbe_b, $font, $text);
#display image
imagepng($image, "$filenameforpng");
}
$text = "<img src='$filename' border='0' alt='email' />";
return $text;
}
echo Txt2Png("1234567890");
архиф с шрифтами: Перевод текста в картинку

