标签:
//生成图片
$width="100";
$height="50";
//生成一个背景,默认黑色
$img=imagecreatetruecolor($width, $height);
//生成颜色
$background=imagecolorallocate($img,200,200,200);
$white=imagecolorallocate($img,255,255,255);
$blue=imagecolorallocate($img,0,0,64);
//替换背颜色
imagefill($img,0,0,$background);
//加入线条
for ($i=1;$i<=10;$i++){
$x1=rand(0,100);
$y1=rand(0,50);
$x2=rand(0,100);
$y2=rand(0,50);
imageline($img,$x1,$y1, $x2, $y2, imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)));
}
//加入小点
for ($i=1;$i<100;$i++){
imagesetpixel($img, mt_rand(0,100),mt_rand(0, 50), imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)));
}
//加入验证码
$str="abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789";
$code="";
$count=strlen($str)-1;
for($i=1;$i<=4;$i++){
$code .= $str[mt_rand(0,$count)];
}
imagestring($img,12, 20, 20,$code,$blue);
//输出图像
header("content-type:image/png");
imagepng($img);标签:
原文地址:http://blog.csdn.net/czhphp/article/details/46311023