At first, there was a php.ini to see if the GD library was turned on,
Next, we will consider each detail of the image generation step.
<?php
Send a generated image to the browser
Create_image ();
Exit ();
function Create_image ()
{
Let ' s generate a totally random string using MD5
$MD 5 = MD5 (rand (0,999));
We don ' t need a character long string so we trim it down to 5
$pass = substr ($md 5, 10, 5);
Set the image width and height
$width = 100;
$height = 20;
Create the image Resource
$image = Imagecreate ($width, $height);
We are making three colors, white, black and gray
$white = Imagecolorallocate ($image, 255, 255, 255);
$black = imagecolorallocate ($image, 0, 0, 0);
$grey = Imagecolorallocate ($image, 204, 204, 204);
Make the background black
Imagefill ($image, 0, 0, $black);
ADD randomly generated string in white to the image
Imagestring ($image, 3, 3, $pass, $white);
Throw in some lines to make it a little bit harder for all bots to
Break
Imagerectangle ($image, 0,0, $width-1, $height-1, $grey);
Imageline ($image, 0, $height/2, $width, $height/2, $grey);
Imageline ($image, $width/2, 0, $width/2, $height, $grey);
Tell the browser what kind of the ' file is ' come in
Header ("Content-type:image/jpeg");
Output the newly created image in JPEG format
Imagejpeg ($image);
Free up Resources
Imagedestroy ($image);
}
?>
Authentication Code Invocation method
Src= "generate_image.php" width= ">"