Creating a PNG with a TrueType font

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”>

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.