php產生數字字母的驗證碼圖片

來源:互聯網
上載者:User

php產生數字字母的驗證碼圖片

  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. //只含有數字
  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. //含有數字和字母的
  15. for($i=0;$i<4;$i++){
  16. $fontSize=6;
  17. $x=rand(5,10)+$i*100/4;
  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. //幹擾點元素
  25. for($i=0;$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. //幹擾線元素
  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. ?>
複製代碼

以上所述就是本文的全部內容了,希望大家能夠喜歡。

驗證碼, php
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.