1 header('Content-type:text/html;charset=utf-8;'); 2 function imgcode($x,$y,$fontsize,$number,$fontfile,$bet=0) 3 { 4 $initimg=imagecreate($x,$y); 5 $bgcolor=imagecolorallocate($initimg,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)); 6 imagefill($initimg,0,0,$bgcolor); 7 8 for($i=0;$i<150;$i++) 9 { 10 $pxcolor=imagecolorallocate($initimg,mt_rand(0,155),mt_rand(0,155),mt_rand(0,155)); 11 imagesetpixel($initimg,mt_rand(10,$x-10),mt_rand(10,$y-10),$pxcolor); 12 } 13 for($i=0;$i<3;$i++) 14 { 15 $linecolor=imagecolorallocate($initimg,mt_rand(0,155),mt_rand(0,155),mt_rand(0,155)); 16 imageline($initimg,mt_rand(10,30),mt_rand(10,$y-10),mt_rand($x-30,$x-10),mt_rand(10,$y-10),$linecolor); 17 } 18 $str="1234567890abcdefghijklmnopqtuvwxyzABCDEFGHIJKLMNOQWTUVWXYZ"; 19 $strimg=""; 20 $strtotal=""; 21 for($i=0;$i<$number;$i++) 22 { 23 $strimg=substr(str_shuffle($str),0,1); 24 $strtotal.=$strimg; 25 $textcolor=imagecolorallocate($initimg,mt_rand(0,100),mt_rand(0,100),mt_rand(0,100)); 26 imagettftext($initimg,$fontsize,mt_rand(-20,20),($x-$fontsize*$number)/($number+1)+($bet+$fontsize)*$i,($y-$fontsize)/2+$fontsize,$textcolor,realpath($fontfile),$strimg); 27 } 28 29 header('Content-type:image/jpeg'); 30 imagejpeg($initimg,null,100); 31 imagedestroy($initimg); 32 return $strtotal; 33 }
1 $x=isset($_REQUEST['x'])?$_REQUEST['x']:200; 2 $y=isset($_REQUEST['y'])?$_REQUEST['y']:100; 3 $size=isset($_REQUEST['size'])?$_REQUEST['size']:20; 4 $num=isset($_REQUEST['num'])?$_REQUEST['num']:4; 5 $spac=isset($_REQUEST['spac'])?$_REQUEST['spac']:5; 6 imgcode($x,$y,$size,$num,'./FRAMDCN.TTF',$spac);