Generate and output the verification code Image. how to output X images?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.