header("content-type:p_w_picpath/gif");
include 'util.php';
$length = isset($_GET['n']) ? $_GET['n'] : 4;
$w = $length*20;
$h = 25;
$dotnum = 2;
$linenum = 2;
$i =p_w_picpathcreatetruecolor($w,$h);
$bgc =p_w_picpathcolorallocate($i,251,251,251);
p_w_picpathfilledrectangle($i,0,0,$w,$h,$bgc);
//绘制干扰线
for($n=0;$n<$linenum;$n++){
$cc=p_w_picpathcolorallocate($i,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
p_w_picpathline($i,mt_rand(0,$w),mt_rand(0,$h),mt_rand(0,$w),mt_rand(0,$h),$cc);
}
//绘制干扰点
for($n=0;$n<$dotnum;$n++){
$cc=p_w_picpathcolorallocate($i,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
$size=mt_rand(2,6);
p_w_picpathfilledellipse($i,mt_rand(0,$w),mt_rand(0,$h),$size,$size,$cc);
}
$text =getstr($length,true,true);
for($n=0;$n<$length;$n++){
$c = p_w_picpathcolorallocate($i,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
p_w_picpathttftext($i,mt_rand(12,18),mt_rand(-10,10),$n*20,mt_rand(18,22),$c,'b.ttf',substr($text,$n,1));
}
p_w_picpathgif($i);
p_w_picpathdestroy($i);
//util.php
/**
*
功能:返回随机字符串 $len 多少个 $num 是否包含数字 $word 是否包含大写字母
*/
function getString($len=4,$num=true,$word=true){
$str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
if(!$num){
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
}
if(!$word){
$str = 'abcdefghijklmnopqrstuvwxyz';
if($num){
$str = '0123456789abcdefghijklmnopqrstuvwxyz';
}
}
$s = '';
for($i=0;$i<$len;$i++){
$s.=$str[mt_rand(0,strlen($str)-1)];
}
return $s;
}
function getstr($length=4,$num=true,$word=true){
$n=0123456789;
$w='abcdefghijklmnopqrstuvwxyz';
$ww='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$temp='';
if($num && $word){
$t=$n.$w.$ww;
}else if($num){
$t=$n.$w;
}else if($word){
$t=$w.$ww;
}else{
$t=$w;
}
for($i=0;$i<$length;$i++){
$temp.=substr($t,mt_rand(0,strlen($t)-1),1);
}
return $temp;
}
//echo getstr(4,true,false);