Creating a PNG with a TrueType font
We can create PNG image file with TrueType font. We need to create a image using ImageCreate() function. For colouring the image use ImageColorAllocate() function. To write the text on the image use the function ImageTTFText() function that will require a .ttf font file. And altast use ImagePNG to create a PNG file. Below is a sample code that will create a PNG with TrueType Font
<?
Header(”Content-type: image/png”);
$text=$_GET[text];
$im = ImageCreate(630,80);
$blue = ImageColorAllocate($im,0×5B,0×69,0xA6);
$white = ImageColorAllocate($im,255,255,255);
$black = ImageColorAllocate($im,0,0,0);
ImageTTFText($im, 45, 0, 10, 57, $black, “myriad.ttf”, $text);
ImageTTFText($im, 45, 0, 6, 54, $white, “myriad.ttf”, $text);
ImagePNG($im);
?>
<IMG xsrc=”txt.php?text=sample” mce_src=”txt.php?text=sample”>
