Simple php function for image generation verification
Source: Internet
Author: User
This function can generate a simple verification image for input verification. The code is as follows:
Function yzm ($ name, $ width, $ height ){
Header ("Content-type: image/PNG ");
Srand (double) microtime () * 1000000); // play the next seed that generates random numbers to facilitate the use of the following random number generation
Session_start (); // Save the random number to the session.
$ _ SESSION [$ name] = "";
$ Im = imagecreate ($ width, $ height); // specify the image background size.
$ Black = ImageColorAllocate ($ im, 0, 0); // you can specify three colors.
$ White = ImageColorAllocate ($ im, 255,255,255 );
$ Gray = ImageColorAllocate ($ im, 200,200,200 );
Imagefill ($ im, $ gray); // use the area filling method, set)
While ($ authnum = rand () % 100000) <10000 );
$ _ SESSION [$ name] = $ authnum;
Imagestring ($ im, 5, 10, 3, $ authnum, $ black );
For ($ I = 0; $ I <200; $ I ++) // add interference pixels
{
$ Randcolor = ImageColorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
Imagesetpixel ($ im, rand () % 70, rand () % 30, $ randcolor );
}
ImagePNG ($ im );
ImageDestroy ($ im );
}?>
Create a php file into yzm. php and call
Call this function.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service