|
<? Php tutorial
/*
* Created on 2011-3-11
* Programmer: xiaoyao, QQ: 1045195056
Verify the input value and $ _ SESSION ['check _ pic '] value
*/
Session_start ();
Function RandAscii ($ number) {// $ number generates numbers and letters
$ Arr = array ('0', '1', '2', '3', '4', '5', '6', '7 ', '8', '9 ',
'A', 'B', 'C', 'D', 'E', '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; // randomly generated four values are assigned to the session for verification.
$ X = 80;
$ Y = 24;
$ Im = imagecreatetruecolor ($ x, $ y); // create an image
$ Bg = imagecolorallocate ($ im, 255,255,255); // sets the color background.
Imagefill ($ im, 0, 0, $ bg );
$ Wh = imagecolorallocate ($ im, 255,255, 0 );
$ Gray = imagecolorallocate ($ im, 128,128,128 );
$ Yellow = imagecolorallocate ($ im, 255,255, 0 );
$ Red = imagecolorallocate ($ im, 0,255, 0 );
$ ForegroundArr = array (imagecolorallocate ($ im, rand (0, 20), rand (0, 20), rand (0, 20 )),
Imagecolorallocate ($ im, rand (0, 20), rand (0, 10), rand (245,255 )),
Imagecolorallocate ($ im, rand (245,255), rand (0, 20), rand (0, 10 )),
Imagecolorallocate ($ im, rand (245,255), rand (0, 20), rand (245,255 ))
); // Color array of words
// Draw a 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
Imageline ($ im, rand (0, 60), 2, rand (0, 60), 20, $ 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,-30), 5, rand (15, 18), $ foregroundArr [rand (0, 3)], 'c: WindowsFontsArial. ttf', $ rand [0]);
Imagettftext ($ im, 14, rand (50,-50), 24, rand (15, 18), $ foregroundArr [rand (0, 3)], 'c: WindowsFontsArial. ttf', $ rand [1]);
Imagettftext ($ im, 14, rand (50,-50), 43, rand (15, 18), $ foregroundArr [rand (0, 3)], 'c: WindowsFontsArial. ttf', $ rand [2]);
Imagettftext ($ im, 14, rand (30,-30), 62, rand (15, 18), $ foregroundArr [rand (0, 3)], 'c: WindowsFontsArial. ttf', $ rand [3]);
Header ("Content-type: image/jpeg"); // output image
Imagejpeg ($ im );
Imagedestroy ($ im );
?> |