php 手机验证码生成工具,php 生成中文验证码程序

今天无意中想起写验证码数字加汉字,下面是代码比较容易没什么好说

先来看看效果图吧.

还不错吧?

Header("Content-type: image/PNG");//生成图片的类型

$str = "的一是在了不和有大这主中人蚕亿矩";//随便回的你可以自己增加

$Width = 240;//图片高度

$imgHeight = 40;//图片宽度

$C_img = imagecreate($Width,$imgHeight);

$bgColor = ImageColorAllocate($C_img,255,255,255);

$f_font = "heiti.ttf";//这里可以选择其它的字体

$white=imagecolorallocate($C_img,234,185,95);

imagearc($C_img, 150, 8, 20, 20, 75, 170, $white);

imagearc($C_img, 180, 7,50, 30, 75, 175, $white);

imageline($C_img,20,20,180,30,$white);

imageline($C_img,20,18,170,50,$white);

imageline($C_img,25,50,80,50,$white);

$noise_num = 800;//杂点的数据

$line_num = 20;//线条的数量

imagecolorallocate($C_img,0xff,0xff,0xff);

$rectangle_color=imagecolorallocate($C_img,0xAA,0xAA,0xAA);

$noise_color=imagecolorallocate($C_img,0x00,0x00,0x00);

$font_color=imagecolorallocate($C_img,0x00,0x00,0x00);

$line_color=imagecolorallocate($C_img,0x00,0x00,0x00);

for($i=0;$i

imagesetpixel($C_img,mt_rand(0,$Width),mt_rand(0,$imgHeight),$noise_color);

}

for($i=0;$i

imageline($C_img,mt_rand(0,$Width),mt_rand(0,$imgHeight),mt_rand(0,$Width),mt_rand(0,$imgHeight),$line_color);

}

$randnum=rand(0,strlen($str)-4);

if($randnum%2)$randnum =1;

$str = substr($str,$randnum,8);

$str = iconv("GB2312","UTF-8",$str).rand(0,1000);//转换编码

ImageTTFText($C_img, 20, 0, 16, 30, $font_color, $f_font, $str);

ImagePNG($C_img);

ImageDestroy($C_img);

?>

注明:转载请说明原处www.jquerycn.cn

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值