php生成验证码

php生成验证码

php生成验证码

$im = imagecreatetruecolor(100, 40);
$white = imagecolorallocate($im,255, 255, 0);
imagefill($im, 0, 0, $white);
$color = imagecolorallocate($im, 0, 255, 255);
imagerectangle($im, 1, 1,99,39, $color);

$arr = "123456789asdfghjkertyuzxcvbnm";
//echo strlen($arr);
for($i = 0;$i<4;$i++){
  $char = $arr[rand(0,29)];
  $col = imagecolorallocate($im,rand(0,120),rand(0,120), rand(0,120));
  $x = ($i*100/4)+rand(5,10);
  $y = rand(10,20);
  imagestring ($im, 5, $x, $y ,$char, $col );

}

for($i = 0;$i<200;$i++){
  $x = rand(1,99);
  $y = rand(1,39);
  $c = imagecolorallocate($im,rand(0,120),rand(0,120), rand(0,120));
  imagesetpixel($im,$x,$y,$c);
}

for ($i=0; $i < 3; $i++) {
  $x1 = rand(1,99);
  $y1 = rand(1,39);
  $x2 = rand(1,99);
  $y2 = rand(1,39);
  $c = imagecolorallocate($im,rand(0,120),rand(0,120), rand(0,120));
  imageline ($im, $x1 , $y1 , $x2 , $y2 , $c );
}
header("content-type:image/jpg");
imagejpeg($im);
imagedestroy($im);