Create Simple Image Using PHP
Create Simple Image Using PHP
Hello Friends today we learn how to create simple Image using PHP GD Library. This
type of generating dynamic image using php can be useful for many purpose e.g.
Captcha Code Image
First we sholud enable php gd2 php extension.
I will use following php function for generating Image using PHP
imagecreate(width, height)
imagecolorallocate(image source, R, G, B)
imagettftext(image source, font size, angle, x axis, y aixs, text color, font path,
string)
imagepng(image source)
imagedestroy(image source)
Now I write PHP code.
First I define Image using image create function with width 200 and height 80.
Then after I define background color using image color allocate function. In this
function first parameter is image source and other parameter is value of RGB color.
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);