function Auth_code ($width =, $height = $num = 4, $line = 4, $dot = 150) { $length = Floor ($width/$num); Floor: Take integer part length: Average length per paragraph for ($i =0; $i < $num; $i + +) @ $rand. =dechex (Mt_rand (1,15)); $_session[' code ']= $rand;
Create a new artboard with a black bottom $im =imagecreatetruecolor ($width, $height);
Take color $green =imagecolorallocate ($im, 0,255,0); $red = Imagecolorallocate ($im, 255,0,0); $white =imagecolorallocate ($im, 255,255,255); $black = Imagecolorallocate ($im, 0,0,0);
Fill artboard Imagefill ($im, 0,0, $green);
Draw Line for ($i =0; $i < $line; $i + +) { $color =imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255)); Imageline ($im, rand ($width -10), 0,rand (0, $width), $height, $color); } Draw a Point for ($i =0; $i < $dot; $i + +) { $color =imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255)); Imagesetpixel ($im, rand (0, $width), rand (0, $height), $color); } Draw a number for ($i =0; $i < $num; $i + +) { Imagestring ($im, 5,mt_rand ($i * $length +1, ($i + 1) * $length -8), Mt_rand (0, $height -14), $_session[' code ' [$i], $white); }
Output picture Header ("Content-type:image/jpeg"); Imagejpeg ($im); } |