header (' content-type:image/png ');//create canvas and set color, recommend the following method//$im =imagecreate ($width, $height); $im = Imagecreatetruecolor (200,100) Or Die (' cannot Initialize GD image ');//Create Background color $bg=imagecolorallocate ($im, 255,255,255); $line =imagecolorallocatealpha ($im, Mt_rand (50,255), Mt_rand (50,255), Mt_rand (50,255), Mt_rand (20,60)), Imagefill ($im, 0,0, $BG); for ($i =0; $i <4;$ i++) {$fontSize =mt_rand (40,80); $fontColor =imagecolorallocatealpha ($im, Rand (0,120), Rand (0,120), Rand (0,120), Rand (20,80)); $data = "abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ0123456789"; $fontContent =substr ($data, Rand (0,strlen ($DATA)), 1); $captcha _code.= $fontContent; $x = ($i *100/4) +rand (10,30); $y =10*rand (2,6); Imagestring ($im, $fontSize, $x, $y, $fontContent, $fontColor);} Increase the interference point for ($i =0; $i <200; $i + +) {$pixel =imagecolorallocatealpha ($im, Mt_rand (50,255), Mt_rand (50,255), Mt_rand ( 50,255), Mt_rand (20,60)); Imagesetpixel ($im, Mt_rand (0,200), Mt_rand (0,100), $pixel);} Add interference line for ($i =0; $i <5; $i + +) {imagesetthickness ($im, Mt_rand (1,5)); $line =imagecolorallocatealpha ($im, Rand (0,120), Rand (0,120), Rand (0,120), Rand (40,80)); Imageline ($im, Mt_ranD (0,200), Mt_rand (0,100), Mt_rand (0,200), Mt_rand (0,100), $line);} Imagepng ($im);//Destroy the object to facilitate system resource recovery Imagedestroy ($IM);
This is the most basic PHP captcha code
PHP Basic code for verification Code