<?php function a($n,$w,$h){ $img = imagecreatetruecolor($w, $h); $black = imagecolorallocate($img, 0x00, 0x00, 0x00); $green = imagecolorallocate($img, 0x00, 0xFF, 0x00); $white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF); imagefill($img,0,0,$white);//生成随机的验证码 $code = ''; $x = 10 ; $y = 13 ; for($i = 0; $i <n; $i++) { $tmp = rand(0, 9); $randcolor = imagecolorallocate($img, rand(0,180), rand(0,180), rand(0,180));//随机色 imagestring($img, 5, $x, $y, $tmp, $randcolor); $code .= $tmp; $x += rand(12,25); $y = 13 + rand(-15, 15); //加入干扰线 $lx1 = rand(0, 100); $ly1 = rand(0, 40); $lx2 = rand(0, 100); $ly2 = rand(0, 40); $randcolor = imagecolorallocate($img, rand(0,255), rand(0,255), rand(0,255)); imageline($img,$lx1,$ly1,$lx2,$ly2,$randcolor); } //加入噪点干扰 for($i=0;$i<50;$i++) { imagesetpixel($img, rand(0, $w) , rand(0, $h) , $black); imagesetpixel($img, rand(0, $w) , rand(0, $h) , $green); } //输出验证码 header("content-type: image/png"); imagepng($img); imagedestroy($img); } a(5,100,40);
ChinaCJM