- Session_start ();
- Header ('content-type: image/png ');
- // Create an image
- $ Im = imagecreate ($ x = 130, $ y = 45 );
- $ Bg = imagecolorallocate ($ im, rand (50,200), rand (0,155), rand (0,155); // The first time on imagecolorallocate () will fill the background color for the image based on the color palette.
- $ FontColor = imageColorAllocate ($ im, 255,255,255); // font color
- $ Fontstyle = 'rock. ttf'; // the font style, which can be found in the c: \ windows \ Fonts \ folder. I put it in the and authcode. the PHP file is in the same directory. other font styles can be replaced here.
- // Generate random characters
- For ($ I = 0; $ I <4; $ I ++ ){
- $ RandAsciiNumArray = array (rand (48, 57), rand (65, 90 ));
- $ RandAsciiNum = $ randAsciiNumArray [rand (0, 1)];
- $ RandStr = chr ($ randAsciiNum );
- Imagettftext ($ im, 30, rand ()-rand (), 5 + $ I * 30, rand (), $ fontColor, $ fontstyle, $ randStr );
- $ Authcode. = $ randStr;
- }
- $ _ SESSION ['authcode'] = $ randFourStr; // compare the verification code entered by the user with that entered by the user
- // Interference line
- For ($ I = 0; $ I <8; $ I ++ ){
- $ LineColor = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
- Imageline ($ im, rand (0, $ x), 0, rand (0, $ x), $ y, $ lineColor );
- }
- // Interference point
- For ($ I = 0; I I <250; $ I ++ ){
- Imagesetpixel ($ im, rand (0, $ x), rand (0, $ y), $ fontColor );
- }
- Imagepng ($ im );
- Imagedestroy ($ im );
- ?>
|