background image

// 画干扰线

for($i=0;$i<5;$i++){

$font_color = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));

imagearc($im,mt_rand(-$width,$width),mt_rand(-$height,

$height),mt_rand(30,$width*2),mt_rand(20,$height*2),mt_rand(0,360),mt_rand(0,360),

$font_color);

}

// 画干扰点

for($i=0;$i<50;$i++){

$font_color = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));

imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$font_color);

}

// 画验证码

@imagefttext($im, $size , 0, 5, $size+3, $text_color, 'c://WINDOWS//Fonts//simsun.ttc',$code);

header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");

header("Content-type: image/png");

imagepng($im);

imagedestroy($im);

}

?>

调用示例:

代码示例

:

<?

// 验证码示例

//4 个字符,大小为 20

vCode(4,20);

?>