标签:des color java for c on r ad ef
//设置画布宽度
$image = imagecreatetruecolor(100, 50);
//画布颜色
$bgcolor = imagecolorallocate($image, 255, 255, 255);
// imagefill — 区域填充
imagefill($image, 0, 0, $bgcolor);
//四个随机验证码
// for($i=0;$i<4;$i++){
// $fontsize = 6;//字体大小
// $fontcolor = imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120)); //字体颜色
// $fontcontent = rand(0,9);//随机数字
// //定位
// $x = ($i * 100 / 4)+ rand(5,10); //
// $y = rand(5,10);
// imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
// }
//包含英文字母的验证码
for($i=0;$i<4;$i++){
$fontsize = 6;
$data =‘123456789abcdefghijklmnopqrstuvwxy‘ ;//建立字典
$fontcolor = imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
$fontcontent = substr($data, rand(0,strlen($data)),1);
$x = ($i * 100 / 4)+ rand(5,10);
$y = rand(5,10);
imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
}
//增加干扰点
for($i=0;$i<200;$i++){
$pointcolor = imagecolorallocate($image, rand(50,120), rand(50,120), rand(50,120));
imagesetpixel($image, rand(0,99), rand(0,29), $pointcolor);
}
//增加干扰线
for ($i=0; $i < 4; $i++) {
$linecolor = imagecolorallocate($image, rand(80,220), rand(80,180), rand(90,250)); //线的颜色是随机的
imageline($image, rand(0,99), rand(0,29), rand(0,99), rand(0,29), $linecolor);
}
header("content-type:image/png");
//输出图像
imagepng($image);
//销毁图像
imagedestroy($image);标签:des color java for c on r ad ef
原文地址:http://my.oschina.net/kopa/blog/324036