PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > ThinkPhp教程 > 正文

    修改thinkphp3.1.3验证码图片的代码

    作者:admin来源:B5教程网浏览:时间:2020-09-30 00:07:50我要评论
    导读:thinkphp3.1.3自带的验证码有些难看小编将其更改了一下总算将就能看的过去了!希望例子能给各位有所帮助,代码如下:复制代码代码如下:sta...
    thinkphp3.1.3自带的验证码有些难看小编将其更改了一下总算将就能看的过去了!希望例子能给各位有所帮助,代码如下:
     
     

     

     
    复制代码代码如下:
    1. “static function buildImageVerify($length=4, $mode=1, $type='png', $width=80, $height=30, $verifyName='verify') {
    2.         import('ORG.Util.String');
    3.         $randval = String::randString($length, $mode);
    4.         session($verifyName, md5($randval));
    5.         $width = ($length * 10 + 10) > $width ? $length * 10 + 10 : $width;
    6. $fontcolor=C('fontcolor');
    7.         if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
    8.             $im = imagecreatetruecolor($width, $height);
    9.         } else {
    10.             $im = imagecreate($width, $height);
    11.         }
    12.         $= Array(225, 255, 255, 223);
    13.         $= Array(225, 236, 237, 255);
    14.         $= Array(225, 236, 166, 125);
    15.         $key = mt_rand(0, 3);
    16.  
    17.  
    18.         $backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]);    //背景色(随机) www.111cn.net
    19.         $borderColor = imagecolorallocate($im, 255, 255, 255);                    //边框色
    20.         imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);//着色
    21.         imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
    22.         $stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
    23.         // 干扰
    24.         for ($= 0; $< C('grunm'); $i++) {
    25. $color = imagecolorallocate($im,mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
    26. imagesetthickness($im,2);
    27. imageline($im,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width),mt_rand(0,$height),$color);
    28.         }
    29.  
    30.  
    31.         for ($= 0; $< 25; $i++) {
    32.             imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $stringColor);
    33.         }
    34. //字体显示的位置和颜色
    35.         for ($= 0; $< $length; $i++) {
    36. imagestring($im,50,$i*10+20,8,$randval{$i},$fontcolor);
    37.         }
    38. //www.111cn.net 雪花
    39. for ($i=0;$i<C('hwunm');$i++) {
    40. $color = imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
    41. imagestring($im,mt_rand(1,5),mt_rand(0,$width-1),mt_rand(0,$height-1),mt_rand(1,9),$color);
    42. }
    43.         Image::output($im, $type);
    44.     }

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-83-446-1.html
    相关热词搜索: thinkphp3.1 验证码