php 生成中文验证码

<?php


    Header("Content-type: image/PNG");
    $str="中文内容请多放些";
    $imgWidth = 1000;//图片宽度
    $imgHeight = 40; //图片高度
    $authimg = imagecreate($imgWidth,$imgHeight);
    $bgColor = ImageColorAllocate($authimg,255,255,255);
    $fontfile = "msyh.ttf";
    $white=imagecolorallocate($authimg,234,185,95);
    //干扰线
    imagearc($authimg, 150, 8, 20, 20, 75, 170, $white);
    imagearc($authimg, 180, 7,50, 30, 75, 175, $white);
    imageline($authimg,20,20,180,30,$white);
    imageline($authimg,20,18,170,50,$white);
    imageline($authimg,25,50,80,50,$white);

    $noise_num = 800;
    $line_num = 20;
    imagecolorallocate($authimg,0xff,0xff,0xff);
    $rectangle_color=imagecolorallocate($authimg,0xAA,0xAA,0xAA);
    $noise_color=imagecolorallocate($authimg,0x00,0x00,0x00);
    $font_color=imagecolorallocate($authimg,0x00,0x00,0x00);
    $line_color=imagecolorallocate($authimg,0x00,0x00,0x00);

    //干扰点点点
    for($i=0;$i<$noise_num;$i++){
        imagesetpixel($authimg,mt_rand(0,$imgWidth),mt_rand(0,$imgHeight),$noise_color);
    }
    //干扰线
    for($i=0;$i<$line_num;$i++){
        imageline($authimg,mt_rand(0,$imgWidth),mt_rand(0,$imgHeight),mt_rand(0,$imgWidth),mt_rand(0,$imgHeight),$line_color);
    }
    //随机
    $randnum=rand(0,strlen($str)-4);
    if($randnum%2)$randnum+=1;
    $str = substr($str,$randnum,8);

    $str = iconv("UTF-8","UTF-8",$str);
    imagettftext($authimg, 9, 0, 0, 14, $font_color, $fontfile, $str);
    imagepng($authimg);
    imagedestroy($authimg);

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值