当前位置:Gxlcms > PHP教程 > php生成数字字母的验证码图片

php生成数字字母的验证码图片

时间:2021-07-01 10:21:17 帮助过:25人阅读

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

人气教程排行