<?php Tutorial /* * Created on 2011-3-11 * Programmer:xiaoyao, qq:1045195056 Validation by judging input values and $_session[' check_pic ' values */ Session_Start (); function Randascii ($number) {//$number produces 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); The $_session[' check_pic ']= $rand;//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), Imagecolorallocate ($im, rand (0), rand (0,), rand (245, 255)), Imagecolorallocate ($im, rand (245, 255), rand (0,), rand (0, 1 0), 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 line, 10 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 (a), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [0]); Imagettftext ($im, 14,rand ( -50), Rand (a), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [1]); Imagettftext ($im, 14,rand ( -50), EUR, Rand (a), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [2]); Imagettftext ($im, 14,rand ( -30), 0,3, Rand (a), $foregroundArr [Rand ()], ' C:windowsfontsarial.ttf ', $rand [3]); Header ("Content-type:image/jpeg");//Output picture Imagejpeg ($im); Imagedestroy ($im); ?> |