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:
Copy codeThe 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.