/* * Created on 2011-3-11 * Programmer:xiaoyao, qq:1045195056 Validation by judging the value of the input value and $_session[' Check_pic '] */ Session_Start (); function Randascii ($number) {//$number produce numbers and letters $arr =array (' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' w ', ' V ', ' u ', ' x ', ' y ', ' z '); for ($i =1; $i <= $number; $i + +) { $rand = $rand. $arr [Rand (0,35)]; } return $rand; } $rand =randascii (4); $_session[' check_pic ']= $rand;//A randomly generated four-digit assignment SESSION for validation. $x = 80; $y = 24; $im =imagecreatetruecolor ($x, $y);//Create Picture $BG =imagecolorallocate ($im, 255,255,255);//Set color background Imagefill ($im, 0,0, $BG); $wh =imagecolorallocate ($im, 255,255,0); $grey =imagecolorallocate ($im, 128,128,128); $yellow =imagecolorallocate ($im, 255,255,0); $red =imagecolorallocate ($im, 0,255,0); $FOREGROUNDARR = Array (imagecolorallocate ($im, rand (0,), rand (0,), rand (0, 20)), Imagecolorallocate ($im, rand (0,), rand (0, 245, 255)), Imagecolorallocate ($im, rand (245, 255), rand (0,), rand (0, 10)), Imagecolorallocate ($im, rand (245, 255), rand (0,), rand (245, 255)) );//Word color array Draw Border $border = Imagecolorallocate ($im, 133, 153, 193); Imagerectangle ($im, 0, 0, $x-1, $y-1, $border); for ($i =0; $i <10; $i + +) {//Draw interference lines, 10 strips Imageline ($im, Rand (0,60), 2,rand (0,60), $yellow); } for ($j =0; $j <100; $j + +) { Imagesetpixel ($im, Rand ()%76,rand ()%20, $red); } Imagestring ($im, 6,15,8, $rand, $WH);//font size 1-5 Imagettftext ($im, 14,rand ( -30), 5, Rand (All), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [0]); Imagettftext ($im, 14,rand ( -50), Rand (at), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [1]; Imagettftext ($im, 14,rand ( -50), A, rand (at), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [2]; Imagettftext ($im, 14,rand ( -30), 0,3, Rand, $FOREGROUNDARR [rand ()], ' C:windowsfontsarial.ttf ', $rand [3]); Header ("Content-type:image/jpeg");//Output picture Imagejpeg ($im); Imagedestroy ($im); ?> |