Displaying text using GD
In this example we show you how to create an image using the GD library and then add text to it . We will go through the process of creating an image using ImageCreate , allocating colors , displaying text and then rendering the image.
Code :
<?php
Header("Content-type: image/jpeg");
//create a new image
$image = ImageCreate(200,200);
//create white (for background )
$white = ImageColorAllocate($image ,255,255,255);
//create blue for text
$blue = ImageColorAllocate($image , 0,0,255);
//OK lets create our white background
ImageFilledRectangle($image ,0,0,200,200,$white);
//display some text
for ($i=1; $i <= 5; $i++)
ImageString($image,$i,15,$i*10,'beginners PHP',$blue);
//output image to browser as a JPEG
ImageJPEG($image);
//clean up by destroying the image
ImageDestroy($image);
?>
Example :