Generate and output the verification code Image. how to output X images?
$ Num = "";
For ($ I = 0; $ I <4; $ I ++ ){
$ Num. = rand (0, 9 );
}
Session_start ();
$ _ SESSION ["Checknum"] = $ num;
Header ("Content-type: image/png ");
Srand (double) microtime () * 1000000 );
$ Im = @ imagecreate (60, 20 );
@ Imagecolorallocate ($ im, 255,255,255 );
$ Black = imagecolorallocate ($ im, 0, 0 );
$ Gray = imagecolorallocate ($ im, 200,200,200 );
Imagefill ($ im, 0, 0, $ gray );
$ Style = array ($ black, $ gray, $ gray );
Imagesetstyle ($ im, $ style );
$ Y1 = rand (0, 20 );
$ Y2 = rand (0, 20 );
$ Y3 = rand (0, 20 );
$ Y4 = rand (0, 20 );
Imageline ($ im, 0, $ y1, 60, $ y3, IMG_COLOR_STYLED );
Imageline ($ im, 0, $ y2, 60, $ y4, IMG_COLOR_STYLED );
For ($ I = 0; $ I <80; $ I ++ ){
Imagesetpixel ($ im, rand (0, 60), rand (0, 20), $ black );
}
$ Strx = rand (3, 8 );
For ($ I = 0; $ I <4; $ I ++ ){
$ Strpos = rand (1, 6 );
Imagestring ($ im, 5, $ strx, $ strpos, substr ($ num, $ I, 1), $ black );
$ Strx + = rand (8, 12 );
}
Imagepng ($ im );
Imagedestroy ($ im );
?>
Reply to discussion (solution)
1. GD extension not loaded
2. the program file has a BOM header.
For details, refer to the following:
Http://blog.csdn.net/u011619326/article/details/37744855
Remove the top Chinese character, and modify the session_start ().
Session_start ();
$ Num = "";
For ($ I = 0; $ I <4; $ I ++ ){
$ Num. = rand (0, 9 );
}
$ _ SESSION ["Checknum"] = $ num;
Header ("Content-type: image/png ");
Srand (double) microtime () * 1000000 );
$ Im = @ imagecreate (60, 20 );
@ Imagecolorallocate ($ im, 255,255,255 );
$ Black = imagecolorallocate ($ im, 0, 0 );
$ Gray = imagecolorallocate ($ im, 200,200,200 );
Imagefill ($ im, 0, 0, $ gray );
$ Style = array ($ black, $ gray, $ gray );
Imagesetstyle ($ im, $ style );
$ Y1 = rand (0, 20 );
$ Y2 = rand (0, 20 );
$ Y3 = rand (0, 20 );
$ Y4 = rand (0, 20 );
Imageline ($ im, 0, $ y1, 60, $ y3, IMG_COLOR_STYLED );
Imageline ($ im, 0, $ y2, 60, $ y4, IMG_COLOR_STYLED );
For ($ I = 0; $ I <80; $ I ++ ){
Imagesetpixel ($ im, rand (0, 60), rand (0, 20), $ black );
}
$ Strx = rand (3, 8 );
For ($ I = 0; $ I <4; $ I ++ ){
$ Strpos = rand (1, 6 );
Imagestring ($ im, 5, $ strx, $ strpos, substr ($ num, $ I, 1), $ black );
$ Strx + = rand (8, 12 );
}
Imagepng ($ im );
Imagedestroy ($ im );
?>
1. GD extension not loaded
2. the program file has a BOM header.
I said 2: You only responded to 1:
Are you not responsible for yourself?
I said 2: You only responded to 1:
Are you not responsible for yourself?
Thank you.
I said 2: You only responded to 1:
Are you not responsible for yourself?
It's okay to use HTML to display images in files,
You can use the php image processing function to display your own images.
Your
Is it in the program file?
Your
Is it in the program file?
Well. I have read an article http://blog.csdn.net/nicolase/article/details/7020970.
Thank you.