<?php
header("Content-type: image/png");
gd_info();
$num=5;//生成验证码的字母个数
$type=2;//验证码的类型,0表示只有数字,1表示数字和小写字母,2表示数字和大写字母
$str=getCode($num,$type);
$width=$num*20;
$hight=30;
$im=imagecreatetruecolor($width,$hight);
$color=imagecolorallocate($im,100,100,100);
$bg = imagecolorallocate($im,255,2,255);
imagefill($im,0,0,$bg);
###添加干扰点
for($i=0;$i<200;$i++){
imagesetpixel($im,rand(0,$width),rand(0,$hight),$color);
}
###添加干扰线
for($i=0;$i<5;$i++){
imageline($im,rand(0,$width),rand(0,$hight),rand(0,$width),rand(0,$hight),$color);
}
####在画布上画字符
for($i=0;$i<$num;$i++){
imagechar($im,1000,5+(18*$i),8,$str[$i],$color);//图像源,字体大小,倾斜角度(0为不倾斜),起始x坐标,起始y坐标,颜色,字体文件,内容
}
//ob_clean();//清除缓冲区内
imagepng($im);
imagedestroy($im);
function getCode($num,$type)
{
$content="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$t=array(9,35,strlen($content)-1);
$c="";
for($i=0;$i<$num;$i++)
{
$c.=$content[rand(0,$t[$type])];
}
return $c;
}
?>
共同學習,寫下你的評論
評論加載中...
作者其他優質文章