Php simple verification code & lt ;! -- * @ Copyright (c) 2011 * @ author: Ernest * @ time: 2011 * @ version: new -- & gt; & lt ;? PhpclassVerifyImg {public $ fontSize = 1 php simple verification code
Length; $ I ++) {// generate a string $ strNum. = $ strings [rand (0, $ count-1)];} session_start (); $ _ SESSION ["verifycode"] = $ strNum; $ this-> im = imagecreate ($ this-> width, $ this-> height); $ backgroundcolor = imagecolorallocate ($ this-> im, 255,255,255 ); // Generate the background color $ frameColor = imageColorAllocate ($ this-> im, 0,255, 0); for ($ I = 0; $ I <$ this-> length; $ I ++) {$ charY = ($ this-> height + 9)/2 + rand (- 1, 1); // define the Y coordinate of the character $ charX = $ I * 15 + 8; // define the X coordinate of the character // $ text_color = imagecolorallocate ($ this-> im, 255, 0, 0); // Generate the character color $ text_color = imagecolorallocate ($ this-> im, mt_rand (50,255), mt_rand (50,128), mt_rand (50,200 )); $ angle = rand (-20, 20); // Generate the character angle // write the imagettftext character ($ this-> im, $ this-> fontSize, $ angle, $ charX, $ charY, $ text_color, $ this-> font, $ strNum [$ I]);} for ($ I = 0; $ I <= 5; $ I ++) {// Cyclically draw the background line $ linecolor = imagecolorallocate ($ this-> im, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 )); $ linex = mt_rand (1, $ this-> width-1); $ liney = mt_rand (1, $ this-> height-1); imageline ($ this-> im, $ linex, $ liney, $ linex + mt_rand (0, 4)-2, $ liney + mt_rand (0, 4)-2, $ linecolor );} for ($ I = 0; $ I <= 32; $ I ++) {// draws the background point cyclically to generate the pitting effect $ pointcolor = imagecolorallocate ($ This-> im, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255); imagesetpixel ($ this-> im, mt_rand (1, $ this-> width-1), mt_rand (1, $ this-> height-1), $ pointcolor);} imagerectangle ($ this-> im, 0, 0, $ this-> width-1, $ this-> height-1, $ frameColor); // draw the border ob_clean (); header ('content-type: image/png '); imagepng ($ this-> im); imagedestroy ($ this-> im); }}$ img = new VerifyImg (); $ img -> Build ();?>