If you want to use the PHP drawing function, you must first enable the function of this module. Just remove the comments before php_gd2.dll in PHP. ini.
Draw a picture below:
CopyCode The Code is as follows: <? PHP
Session_start ();
// Generate a verification code Image
Header ("Content-Type: image/PNG ");
$ Im = imagecreate (); // draw an image with the specified width and height
$ Back = imagecolorallocate ($ im, 245,245,245); // defines the background color.
Imagefill ($ im, $ back); // fill the background color in the image you just drew
$ Vcodes = "";
Srand (double) microtime () * 1000000 );
// Generate four digits
For ($ I = 0; $ I <4; $ I ++ ){
$ Font = imagecolorallocate ($ im, Rand (100,255), Rand (0,100), Rand (100,255); // generate a random color
$ Authnum = rand (1, 9 );
$ Vcodes. = $ authnum;
Imagestring ($ im, 5, 2 + $ I * 10, 1, $ authnum, $ font );
}
$ _ Session ['vcode'] = $ vcodes;
For ($ I = 0; $ I <100; $ I ++) // Add interference pixels
{
$ Randcolor = imagecolorallocate ($ im, Rand (0,255), Rand (0,255), Rand (0,255 ));
Imagesetpixel ($ im, Rand () % 70, Rand () % 30, $ randcolor); // draws the pixel point function
}
Imagepng ($ IM );
Imagedestroy ($ IM );
?>
This is basically how it works. In fact, if you add a watermark to an image, you can simply write it in the image.
Used directly
enter the name of the PHP file.