Php generates a verification code Image of numbers and letters

Source: Internet
Author: User
Php generates a verification code Image of numbers and letters

Php generates a verification code Image of numbers and letters

  1. Header ('content-Type: image/png ');
  2. $ Image = imagecreatetruecolor (100, 30 );
  3. $ Color = imagecolorallocate ($ image, 255,255,255 );
  4. Imagefill ($ image, 20, 20, $ color );
  5. // Only contains numbers
  6. // For ($ I = 0; $ I <4; $ I ++ ){
  7. // $ Font = 6;
  8. // $ X = rand (5, 10) + $ I * 100/4;
  9. // $ Y = rand (8, 15 );
  10. // $ String = rand (0, 9 );
  11. // $ Color = imagecolorallocate ($ image, rand (0,120), rand (0,120), rand (0,120 ));
  12. // Imagestring ($ image, $ font, $ x, $ y, $ string, $ color );
  13. //}
  14. // Contains numbers and letters
  15. For ($ I = 0; $ I <4; $ I ++ ){
  16. $ FontSize = 6;
  17. $ X = rand (100/4) + $ I;
  18. $ Y = rand (5, 15 );
  19. $ Data = 'abcdefghijklmnopqrstuvwxyz123456789 ';
  20. $ String = substr ($ data, rand (0, strlen ($ data), 1 );
  21. $ Color = imagecolorallocate ($ image, rand (0,120), rand (0,120), rand (0,120 ));
  22. Imagestring ($ image, $ fontSize, $ x, $ y, $ string, $ color );
  23. }
  24. // Interference point element
  25. For ($ I = 0; I I <200; $ I ++ ){
  26. $ PointColor = imagecolorallocate ($ image, rand (100,255), rand (100,255), rand (100,255 ));
  27. Imagesetpixel ($ image, rand (0,100), rand (0, 30), $ pointColor );
  28. }
  29. // Interference line element
  30. For ($ I = 0; $ I <2; $ I ++ ){
  31. $ LinePoint = imagecolorallocate ($ image, rand (150,255), rand (150,255), rand (150,255 ));
  32. Imageline ($ image, rand (10, 50), rand (10, 20), rand (80, 90), rand (15, 25), $ linePoint );
  33. }
  34. Imagepng ($ image );
  35. Imagedestroy ($ image );
  36. ?>

The above is all the content of this article. I hope you will like it.

Verification code, php

Related Article

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.