What Is GD Library?

GD is an open source library which is mainly used for creating images dynamically like captcha, charts, graphics etc.It is used for creating PNG,JPEG and GIF kind of images.It was developed by Thomas Boutell and is now maintained by Pierre-A.Joye.

Let us create an image or captcha by using GD library.

<?php

//set height and width for rectangular image(captcha)
$width =160;
$height =160;

//amount of background noise to add in captcha image
$noise_level = 15;

//generate the random value one at a time by using rand function
$code=rand(1000,9999);

//save it in SESSION variable so that data can be carried from one page to another page.
session_start();
$_SESSION[“code”]=$code;

//create the image resource
$img = imagecreatetruecolor($width, $height);
$col1 = imagecolorallocate($img, 30, 180, 40); //color 1
$col2 = imagecolorallocate($img,170, 255, 195);//color 2
$ns = imagecolorallocate($img, 200, 200, 200);//noise color

//fill the image resource with the color 1
imagefill($img, 0, 0, $col1);

//Add the random code of string to the image
imagestring($img, 25, 40, 18, $code, $col2);//imagestring

// Add some noise to the image.
for ($i = 0; $i < $noise_level; $i++) {
for ($j = 0; $j < $noise_level; $j++) {
imagesetpixel(
$img,
rand(0,$width),
rand(0,$height),
$ns
);
}
}

//tell the browser that this is an image by throwing header() from server side to client side.

header(‘Content-type:image/gif’);

//generate the gif image
imagegif($img);

//destroy the resource of image created
imagedestroy($img);
?>

SynapseIndia claim top notch services in the field of IT sectors within tight deadlines.Employee at SynapseIndia never gets complaints from clients for deadlines, So, it is one of the trusted offshore software development company, that is easily completed the projects with a minimum span of time. IT Mentor & an Entrepreneur SynapseIndia CEO Shamit Khemka is responsible to make this organization robust and reliable.You can check feedback and reviews given by clients on various projects completed by us.

The Employment Bond is basically an agreement which the company and the employee enter into which among the other terms contained therein states that in consideration of the training given to the Employee and the money spent by the company in imparting such training, the Employee will remain in the services of the company for a particular period.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>