Php verification class
[PHP] code
Font = "font ". DIRECTORY_SEPARATOR. "arial. ttf ";}/** verification code generation function */private function create_code () {$ code =" "; for ($ I = 0; $ I <$ this-> code_len; $ I ++) {$ code. = $ this-> code_str [mt_rand (0, strlen ($ this-> code_str)-1)] ;}$ this-> code = $ code ;} /** get verification code */public function getcode () {return strtoupper ($ this-> code);}/** create image handle */public function getimg () {$ w = $ this-> width; $ h = $ this-> height; $ img = imagecr Eatetruecolor ($ w, $ h); $ bg_color = imagecolorallocate ($ img, hexdec (substr ($ bg_color, 1, 2), hexdec (substr ($ img, 3, 2 )), hexdec (substr ($ img, 5, 2); imagefill ($ img, $ bg_color); $ this-> img = $ img; $ this-> create_font (); $ this-> create_pix (); $ this-> show_code ();}/** create font */public function create_font () {$ this-> create_code (); $ color = $ this-> font_color; $ font_color = imagecolorallocate ($ this-> img, hexdec (su Bstr ($ color,), hexdec (substr ($ color,), hexdec (substr ($ color ))); $ x = $ this-> width/$ this-> code_len; for ($ I = 0; $ I <$ this-> code_len; $ I ++) {imagettftext ($ this-> img, $ this-> font_size, mt_rand (-30, 30), $ x * $ I + mt_rand (3, 6 ), mt_rand ($ this-& gt; height/1.2, $ this-& gt; height-5), $ font_color, $ this-& gt; font, $ this-& gt; code [$ I]);} $ this-> font_color = $ font_color;}/** writer interference */private function create_pix () {$ Pix_color = $ this-> font_color; for ($ I = 0; $ I <100; $ I ++) {imagesetpixel ($ this-> img, mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), $ pix_color);} for ($ j = 0; $ j <2; $ j ++) {imagesetthickness ($ this-> img, mt_rand (2, 4); imageline ($ this-> img, mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), $ pix_color );}} /** display code */private function show_code () {header ("Content -Type: image/png "); imagepng ($ this-> img); imagedestroy ($ this-> img); }}?>[PHP] code
Font = "font ". DIRECTORY_SEPARATOR. "arial. ttf ";}/** verification code generation function */private function create_code () {$ code =" "; for ($ I = 0; $ I <$ this-> code_len; $ I ++) {$ code. = $ this-> code_str [mt_rand (0, strlen ($ this-> code_str)-1)] ;}$ this-> code = $ code ;} /** get verification code */public function getcode () {return strtoupper ($ this-> code);}/** create image handle */public function getimg () {$ w = $ this-> width; $ h = $ this-> height; $ img = imagecr Eatetruecolor ($ w, $ h); $ bg_color = imagecolorallocate ($ img, hexdec (substr ($ bg_color, 1, 2), hexdec (substr ($ img, 3, 2 )), hexdec (substr ($ img, 5, 2); imagefill ($ img, $ bg_color); $ this-> img = $ img; $ this-> create_font (); $ this-> create_pix (); $ this-> show_code ();}/** create font */public function create_font () {$ this-> create_code (); $ color = $ this-> font_color; $ font_color = imagecolorallocate ($ this-> img, hexdec (su Bstr ($ color,), hexdec (substr ($ color,), hexdec (substr ($ color ))); $ x = $ this-> width/$ this-> code_len; for ($ I = 0; $ I <$ this-> code_len; $ I ++) {imagettftext ($ this-> img, $ this-> font_size, mt_rand (-30, 30), $ x * $ I + mt_rand (3, 6 ), mt_rand ($ this-& gt; height/1.2, $ this-& gt; height-5), $ font_color, $ this-& gt; font, $ this-& gt; code [$ I]);} $ this-> font_color = $ font_color;}/** writer interference */private function create_pix () {$ Pix_color = $ this-> font_color; for ($ I = 0; $ I <100; $ I ++) {imagesetpixel ($ this-> img, mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), $ pix_color);} for ($ j = 0; $ j <2; $ j ++) {imagesetthickness ($ this-> img, mt_rand (2, 4); imageline ($ this-> img, mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), $ pix_color );}} /** display code */private function show_code () {header ("Content -Type: image/png "); imagepng ($ this-> img); imagedestroy ($ this-> img); }}?>