<?PHP/** * PHP generated Verification code * @param $width Canvas width * @param $height Canvas Height * @param $vcodelen captcha length * @param $pointnum number of interference pixels * @param $li Nenum number of interfering lines * * idea: Create Captcha canvas, generate and fill background color, generate CAPTCHA content/interference pixel dots/lines, populate to canvas, output. */ $width= 100; $height= 30; $vcodelen= 4; $pointnum= 200; $linenum= 3; //Create a canvas $image= Imagecreatetruecolor ($width,$height); //Create a color block $bgcolor= Imagecolorallocate ($image, 255, 255, 255); //Fill Canvas background colorImagefill ($image, 0, 0,$bgcolor); //Verification Code Content for($i= 0;$i<$vcodelen;$i++) { //Font Size $fontsize= 5; //font color, color within the bounds of the random $fontcolor= Imagecolorallocate ($image,Rand(0,120),Rand(0,120),Rand(0,120)); $data= ' abcdefghijklmnopqrstuvwxyz0123456789 '; //Verification code content is randomly intercepted within the above string $fontcontent=substr($data,Rand(0,strlen($data)), 1); //String Display location $x= ($i*$width/4) +Rand(5,15); $y=Rand(5,10); //string Fill picture//imagestring font size optional 1-5, font larger need to use Imagettftext function (font file required)Imagestring ($image,$fontsize,$x,$y,$fontcontent,$fontcolor); //Imagettftext ($image, $fontsize, 0, $x, $y, $fontcolor, '/font/geneva.dfont ', $fontcontent); } //interfering pixel points for($i= 0;$i<$pointnum;$i++) { $pointcolor= Imagecolorallocate ($image,Rand(0,120),Rand(0,120),Rand(0,120)); //Canvas fill pixel point functionImagesetpixel ($image,Rand(0,$width),Rand(0,$height),$pointcolor); } //interfering Lines for($i= 0;$i<$linenum;$i++) { $linecolor= Imagecolorallocate ($image,Rand(0,120),Rand(0,120),Rand(0,120)); //Canvas fill Line functionImageline ($image,Rand(0,$width),Rand(0,$height),Rand(0,$width),Rand(0,$height),$linecolor); } //Picture output Format Header(' Content-type:image/png '); //output Verification Code pictureImagepng ($image); //destroying the canvasImagedestroy ($image);?>
PHP Generate Verification Code