导读:thinkphp3.1.3自带的验证码有些难看小编将其更改了一下总算将就能看的过去了!希望例子能给各位有所帮助,代码如下:复制代码代码如下:sta...
thinkphp3.1.3自带的验证码有些难看小编将其更改了一下总算将就能看的过去了!希望例子能给各位有所帮助,代码如下:
复制代码代码如下:
- “static function buildImageVerify($length=4, $mode=1, $type='png', $width=80, $height=30, $verifyName='verify') {
- import('ORG.Util.String');
- $randval = String::randString($length, $mode);
- session($verifyName, md5($randval));
- $width = ($length * 10 + 10) > $width ? $length * 10 + 10 : $width;
- $fontcolor=C('fontcolor');
- if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
- $im = imagecreatetruecolor($width, $height);
- } else {
- $im = imagecreate($width, $height);
- }
- $r = Array(225, 255, 255, 223);
- $g = Array(225, 236, 237, 255);
- $b = Array(225, 236, 166, 125);
- $key = mt_rand(0, 3);
-
-
- $backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]); //背景色(随机) www.111cn.net
- $borderColor = imagecolorallocate($im, 255, 255, 255); //边框色
- imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);//着色
- imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
- $stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
- // 干扰
- for ($i = 0; $i < C('grunm'); $i++) {
- $color = imagecolorallocate($im,mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
- imagesetthickness($im,2);
- imageline($im,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width),mt_rand(0,$height),$color);
- }
-
-
- for ($i = 0; $i < 25; $i++) {
- imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $stringColor);
- }
- //字体显示的位置和颜色
- for ($i = 0; $i < $length; $i++) {
- imagestring($im,50,$i*10+20,8,$randval{$i},$fontcolor);
- }
- //www.111cn.net 雪花
- for ($i=0;$i<C('hwunm');$i++) {
- $color = imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
- imagestring($im,mt_rand(1,5),mt_rand(0,$width-1),mt_rand(0,$height-1),mt_rand(1,9),$color);
- }
- Image::output($im, $type);
- }