免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3792 | 回复: 1
打印 上一主题 下一主题

php生成验证码图片 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-07-13 13:10 |只看该作者 |倒序浏览
  1. <?php

  2. header ('Content-Type: image/png');
  3. $image=imagecreatetruecolor(100, 30);
  4. $color=imagecolorallocate($image, 255, 255, 255);
  5. imagefill($image, 20, 20, $color);
  6. //只含有数字
  7. // for($i=0;$i<4;$i++){
  8.     // $font=6;
  9.     // $x=rand(5,10)+$i*100/4;
  10.     // $y=rand(8, 15);
  11.     // $string=rand(0, 9);
  12.     // $color=imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
  13.     // imagestring($image, $font, $x, $y, $string, $color);
  14. // }

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

论坛徽章:
26
2015亚冠之胡齐斯坦钢铁
日期:2015-06-25 21:40:202015亚冠之柏斯波利斯
日期:2015-08-31 17:03:192015亚冠之柏斯波利斯
日期:2015-11-07 13:10:00程序设计版块每日发帖之星
日期:2015-11-10 06:20:00每日论坛发贴之星
日期:2015-11-10 06:20:00程序设计版块每日发帖之星
日期:2015-11-26 06:20:00程序设计版块每日发帖之星
日期:2015-12-02 06:20:00黄金圣斗士
日期:2015-12-07 17:57:4615-16赛季CBA联赛之天津
日期:2015-12-23 18:34:14程序设计版块每日发帖之星
日期:2016-01-02 06:20:00程序设计版块每日发帖之星
日期:2016-01-06 06:20:00每日论坛发贴之星
日期:2016-01-06 06:20:00
2 [报告]
发表于 2015-07-15 18:56 |只看该作者
谢谢,我是新手,刚刚学习 ...
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP