diff --git a/src/include/data/fonts/1.ttf b/src/include/data/fonts/1.ttf index 3e66a8c9..139f0b43 100755 Binary files a/src/include/data/fonts/1.ttf and b/src/include/data/fonts/1.ttf differ diff --git a/src/include/data/fonts/2.ttf b/src/include/data/fonts/2.ttf index 581d5cee..bb1abf6b 100755 Binary files a/src/include/data/fonts/2.ttf and b/src/include/data/fonts/2.ttf differ diff --git a/src/include/data/fonts/3.ttf b/src/include/data/fonts/3.ttf index 51d6111d..50dd77d2 100755 Binary files a/src/include/data/fonts/3.ttf and b/src/include/data/fonts/3.ttf differ diff --git a/src/include/data/fonts/4.ttf b/src/include/data/fonts/4.ttf new file mode 100644 index 00000000..d232902c Binary files /dev/null and b/src/include/data/fonts/4.ttf differ diff --git a/src/include/data/fonts/5.ttf b/src/include/data/fonts/5.ttf new file mode 100644 index 00000000..f7cd9986 Binary files /dev/null and b/src/include/data/fonts/5.ttf differ diff --git a/src/include/data/fonts/ggbi.ttf b/src/include/data/fonts/6.ttf old mode 100755 new mode 100644 similarity index 100% rename from src/include/data/fonts/ggbi.ttf rename to src/include/data/fonts/6.ttf diff --git a/src/plus/vdimgck.php b/src/plus/vdimgck.php index b126626d..87c87df2 100755 --- a/src/plus/vdimgck.php +++ b/src/plus/vdimgck.php @@ -1,4 +1,5 @@ 14, + 'font_size' => 20, 'img_height' => $safe_wheight, - 'word_type' => (int)$safe_codetype, // 1:数字 2:英文 3:单词 + 'word_type' => (int)$safe_codetype, // 1:数字 2:英文 3:单词 'img_width' => $safe_wwidth, 'use_boder' => TRUE, - 'font_file' => DEDEINC.'/data/fonts/'.mt_rand(1,3).'.ttf', - 'wordlist_file' => DEDEINC.'/data/words/words.txt', - 'filter_type' => 5); + 'font_file' => DEDEINC . '/data/fonts/' . mt_rand(1, 6) . '.ttf', + 'wordlist_file' => DEDEINC . '/data/words/words.txt', + 'filter_type' => 5 +); -$enkey = substr(md5(substr($cfg_cookie_encode,0,5)),0,10); -$sessSavePath = DEDEDATA."/sessions_{$enkey}"; -if ( !is_dir($sessSavePath) ) mkdir($sessSavePath); +$enkey = substr(md5(substr($cfg_cookie_encode, 0, 5)), 0, 10); +$sessSavePath = DEDEDATA . "/sessions_{$enkey}"; +if (!is_dir($sessSavePath)) mkdir($sessSavePath); // Session保存路径 -if(is_writeable($sessSavePath) && is_readable($sessSavePath)){ session_save_path($sessSavePath); } -if(!empty($cfg_domain_cookie)) session_set_cookie_params(0,'/',$cfg_domain_cookie); +if (is_writeable($sessSavePath) && is_readable($sessSavePath)) { + session_save_path($sessSavePath); +} +if (!empty($cfg_domain_cookie)) session_set_cookie_params(0, '/', $cfg_domain_cookie); -if (!echo_validate_image($config)) -{ +if (!echo_validate_image($config)) { // 如果不成功则初始化一个默认验证码 @session_start(); $_SESSION['securimage_code_value'] = strtolower('abcd'); if (function_exists('imagecreatefromjpeg')) { - $im = @imagecreatefromjpeg(DEDEINC.'/data/vdcode.jpg'); + $im = @imagecreatefromjpeg(DEDEINC . '/data/vdcode.jpg'); header("Pragma:no-cache\r\n"); header("Cache-Control:no-cache\r\n"); header("Expires:0\r\n"); @@ -46,34 +49,34 @@ if (!echo_validate_image($config)) header("Pragma:no-cache\r\n"); header("Cache-Control:no-cache\r\n"); header("Expires:0\r\n"); - $c = file_get_contents(DEDEINC.'/data/vdcode.jpg',true); - $size = filesize(DEDEINC.'/data/vdcode.jpg'); - header ('Content-Type: image/x-icon'); - header ("Content-length: $size"); + $c = file_get_contents(DEDEINC . '/data/vdcode.jpg', true); + $size = filesize(DEDEINC . '/data/vdcode.jpg'); + header('Content-Type: image/x-icon'); + header("Content-length: $size"); echo $c; } } -function echo_validate_image( $config = array() ) +function echo_validate_image($config = array()) { @session_start(); - if ( !function_exists('imagettftext') ) - { + if (!function_exists('imagettftext')) { return false; } //主要参数 $font_size = isset($config['font_size']) ? $config['font_size'] : 14; - $img_height = isset($config['img_height']) ? $config['img_height'] : 24; + $img_height = isset($config['img_height']) ? $config['img_height'] : 38; $img_width = isset($config['img_width']) ? $config['img_width'] : 68; - $font_file = isset($config['font_file']) ? $config['font_file'] : DEDEINC.'/data/font/'.mt_rand(1,3).'.ttf'; + $font_file = isset($config['font_file']) ? $config['font_file'] : DEDEINC . '/data/font/' . mt_rand(1, 6) . '.ttf'; $use_boder = isset($config['use_boder']) ? $config['use_boder'] : TRUE; $filter_type = isset($config['filter_type']) ? $config['filter_type'] : 0; //创建图片,并设置背景色 $im = @imagecreate($img_width, $img_height); - imagecolorallocate($im, 255,255,255); + + imagecolorallocate($im, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)); //文字随机颜色 $fontColor[] = imagecolorallocate($im, 0x15, 0x15, 0x15); @@ -84,27 +87,23 @@ function echo_validate_image( $config = array() ) //获取随机字符 $rndstring = ''; - if ($config['word_type'] != 3) - { - for($i=0; $i<4; $i++) - { - if ($config['word_type'] == 1) - { + if ($config['word_type'] != 3) { + for ($i = 0; $i < 4; $i++) { + if ($config['word_type'] == 1) { $c = chr(mt_rand(48, 57)); - } else if($config['word_type'] == 2) - { + } else if ($config['word_type'] == 2) { $c = chr(mt_rand(65, 90)); - if( $c=='I' ) $c = 'P'; - if( $c=='O' ) $c = 'N'; + if ($c == 'I') $c = 'P'; + if ($c == 'O') $c = 'N'; } $rndstring .= $c; } } else { - $chars='abcdefghigklmnopqrstuvwxwyABCDEFGHIGKLMNOPQRSTUVWXWY0123456789'; - $rndstring=''; - $length = rand(4,4); + $chars = 'abcdefghigklmnopqrstuvwxwyABCDEFGHIGKLMNOPQRSTUVWXWY0123456789'; + $rndstring = ''; + $length = rand(4, 4); $max = strlen($chars) - 1; - for($i = 0; $i < $length; $i++) { + for ($i = 0; $i < $length; $i++) { $rndstring .= $chars[mt_rand(0, $max)]; } } @@ -113,51 +112,67 @@ function echo_validate_image( $config = array() ) $rndcodelen = strlen($rndstring); - //背景横线 - $lineColor1 = imagecolorallocate($im, 0xda, 0xd9, 0xd1); - for($j=3; $j<=$img_height-3; $j=$j+3) - { - imageline($im, 2, $j, $img_width - 2, $j, $lineColor1); + // //背景横线 + // $lineColor1 = imagecolorallocate($im, 0xda, 0xd9, 0xd1); + // for ($j = 3; $j <= $img_height - 3; $j = $j + 3) { + // imageline($im, 2, $j, $img_width - 2, $j, $lineColor1); + // } + + // //背景竖线 + // $lineColor2 = imagecolorallocate($im, 0xda, 0xd9, 0xd1); + // for ($j = 2; $j < 100; $j = $j + 6) { + // imageline($im, $j, 0, $j + 8, $img_height, $lineColor2); + // } + + // 增加一些噪线 + for ($i=0; $i < 5; $i++) { + $red = mt_rand(50, 255); + $green = mt_rand(50, 255); + $blue = mt_rand(50, 255); + $tcol = imagecolorallocate($im, $red, $green, $blue); + if (mt_rand(0, 1)) { // Horizontal + $Xa = mt_rand(0, $img_width/2); + $Ya = mt_rand(0, $img_height); + $Xb = mt_rand($img_width/2, $img_width); + $Yb = mt_rand(0, $img_height); + } else { // Vertical + $Xa = mt_rand(0, $img_width); + $Ya = mt_rand(0, $img_height/2); + $Xb = mt_rand(0, $img_width); + $Yb = mt_rand($img_height/2, $img_height); + } + imagesetthickness($im, mt_rand(1, 3)); + imageline($im, $Xa, $Ya, $Xb, $Yb, $tcol); } - //背景竖线 - $lineColor2 = imagecolorallocate($im, 0xda,0xd9,0xd1); - for($j=2;$j<100;$j=$j+6) - { - imageline($im, $j, 0, $j+8, $img_height, $lineColor2); - } //画边框 - if( $use_boder && $filter_type == 0 ) - { + if ($use_boder && $filter_type == 0) { $bordercolor = imagecolorallocate($im, 0x9d, 0x9e, 0x96); - imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $bordercolor); + imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $bordercolor); } //输出文字 $lastc = ''; - for($i=0;$i<$rndcodelen;$i++) - { - $bc = mt_rand(0, 1); + for ($i = 0; $i < $rndcodelen; $i++) { $rndstring[$i] = strtoupper($rndstring[$i]); - $c_fontColor = $fontColor[mt_rand(0,4)]; - $y_pos = $i==0 ? 4 : $i*($font_size+2); - $c = mt_rand(0, 15); - @imagettftext($im, $font_size, $c, $y_pos, 19, $c_fontColor, $font_file, $rndstring[$i]); + $c_fontColor = $fontColor[mt_rand(0, 4)]; + $y_pos = $i == 0 ? 4 : $i * ($font_size + 2); + $c = mt_rand(10, 30); + @imagettftext($im, $font_size, $c, $y_pos, 28, $c_fontColor, $font_file, $rndstring[$i]); $lastc = $rndstring[$i]; } //图象效果 - switch($filter_type) - { + switch ($filter_type) { case 1: - imagefilter ( $im, IMG_FILTER_NEGATE); + imagefilter($im, IMG_FILTER_NEGATE); break; case 2: - imagefilter ( $im, IMG_FILTER_EMBOSS); + imagefilter($im, IMG_FILTER_EMBOSS); break; case 3: - imagefilter ( $im, IMG_FILTER_EDGEDETECT); + imagefilter($im, IMG_FILTER_EDGEDETECT); break; default: break; @@ -170,13 +185,10 @@ function echo_validate_image( $config = array() ) //输出特定类型的图片格式,优先级为 gif -> jpg ->png //dump(function_exists("imagejpeg")); - if(function_exists("imagejpeg")) - { + if (function_exists("imagejpeg")) { header("content-type:image/jpeg\r\n"); imagejpeg($im); - } - else - { + } else { header("content-type:image/png\r\n"); imagepng($im); }