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

原创
2016-07-25 08:44:37 703浏览

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 // $font=6;
  7. // $x=rand(5,10)+$i*100/4;
  8. // $y=rand(8, 15);
  9. // $string=rand(0, 9);
  10. // $color=imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
  11. // imagestring($image, $font, $x, $y, $string, $color);
  12. // }
  13. //含有数字和字母的
  14. for($i=0;$i $fontSize=6;
  15. $x=rand(5,10)+$i*100/4;
  16. $y=rand(5, 15);
  17. $data='abcdefghijklmnopqrstuvwxyz123456789';
  18. $string=substr($data,rand(0, strlen($data)),1);
  19. $color=imagecolorallocate($image,rand(0,120), rand(0,120), rand(0,120));
  20. imagestring($image, $fontSize, $x, $y, $string, $color);
  21. }
  22. //干扰点元素
  23. for($i=0;$i $pointColor=imagecolorallocate($image, rand(100, 255), rand(100, 255), rand(100, 255));
  24. imagesetpixel($image, rand(0, 100), rand(0, 30), $pointColor);
  25. }
  26. //干扰线元素
  27. for($i=0;$i $linePoint=imagecolorallocate($image, rand(150, 255), rand(150, 255), rand(150, 255));
  28. imageline($image, rand(10, 50), rand(10, 20), rand(80,90), rand(15, 25), $linePoint);
  29. }
  30. imagepng($image);
  31. imagedestroy($image);
  32. ?>
复制代码

以上所述就是本文的全部内容了,希望大家能够喜欢。

验证码, php


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。