Слияние кода завершено, страница обновится автоматически
<?php
/**
* @name Captcha Class
* @file captcha_image.cls.php
* @date 2016-08-11 17:40
* @author sancia@foxmail.com
**/
class Captcha_image {
public $image_width = 0;
public $image_height = 0;
public $code_length = 0;
private $im = null;
private $code = '';
private $ttf_file = '';
private $multi_color = array();
private $cur_gmt_time = '';
/**
* @param $image_width integer 图片宽度
* @param $image_height integer 图片高度
* @param $code_length integer 验证码长度
**/
public function __construct( $image_width=120, $image_height=30, $ttf='scood.ttf'){
$base_dir = str_replace('\\','/', dirname(__FILE__));
$this->cur_gmt_time = gmdate('D, d M Y H:i:s'). ' GMT' ;
$this->image_width = $image_width;
$this->image_height = $image_height;
if($ttf ){
$this->ttf_file = $base_dir . '/'. $ttf;
}else{
$this->ttf_file = $base_dir . '/scood.ttf'.;
}
$this->multi_color = array(
array( 102 , 102 ,255 ),
array( 102 , 0 ,0 ),
array( 55 , 187 ,99 ),
array( 51 , 51 ,204 ),
array( 153 , 51 ,0 ),
array( 0 , 96 ,204 ),
array( 220 , 50 ,200 ),
array( 102 , 51 ,204 ),
array( 210 , 20 ,100 ),
array( 0 , 102 ,102 ),
array( 204 , 51 ,102 ),
array( 96 , 146 ,220 ),
array( 255 , 167 ,0 )
);
$this->im = imagecreatetruecolor($this->image_width, $this->image_height);
$fillcolor = imagecolorAllocate($this->im, 255 , 255, 255);
imagefill($this->im, 0, 0, $fillcolor);
}
/**
* 创建 - 验证码
* @access private
**/
private function create_code(){
global $captcha_dict;
$_dict_len = mt_rand( 0 , count( $captcha_dict ) -1 ) ;
$this->code = $captcha_dict[ $_dict_len ] ;
$this->code_length = strlen($this->code ) ;
$_SESSION['securcode'] = strtolower($code);
unset( $captcha_dict ) ;
}
/**
* 绘制 - 线条
* @access private
**/
private function draw_line() {
$color = null;
$line_num = intval( $this->image_height / 4.3 ) ;
$arc_width = intval( $this->image_width / 2.2 ) ;
$arc_height = intval( $this->image_height / 1.8 ) ;
for ($i= 0; $i < $line_num ; $i++) {
$color = imageColorAllocate(
$this->im,
mt_rand( 160, 200 ),
mt_rand( 160, 200 ),
mt_rand( 160, 200 )
);
imagefilledarc(
$this->im,
mt_rand( 5 ,$this->image_width ) ,
mt_rand( 5 ,$this->image_height) ,
$arc_width ,
$arc_height,
0 ,
360 ,
$color,
IMG_ARC_NOFILL
);
}
}
/**
* 绘制 - 图形验证码
* @access
**/
public function draw_word(){
$color_num = 0 ;
$font_size = $this->image_height * 0.66;
$_x = floor($this->image_width / $this->code_length);
$code_rand = count($this->multi_color) - 1;
$rand_color= array() ;
$base_h_zb = $this->image_height / 1.26 ;
for ( $i = 0; $i< $this->code_length; $i++ ) {
$im_roll_jd = mt_rand( -10, 10) ;
$color_num = mt_rand(0, $code_rand);
$rand_color = $this->multi_color[$color_num] ;
$this->fontcolor = imagecolorallocate(
$this->im,
$rand_color[0] ,
$rand_color[1] ,
$rand_color[2]
);
imagettftext(
$this->im,
$font_size ,
$im_roll_jd,
$_x * $i + 5,
$base_h_zb,
$this->fontcolor,
$this->ttf_file,
$this->code[$i]
);
}
}
/**
* 输出图片到浏览器
* @access private
**/
private function browser(){
header('Date: '. $this->cur_gmt_time );
header('Expires: Mon, 1 May 2016 01:01:01 GMT');
header('Last-Modified: '. $this->cur_gmt_time );
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Content-Type: image/gif');
ob_clean();
imagegif($this->im);
}
/**
* 返回验证码
* @access private
**/
public function get_code(){
return $this->code;
}
/**
* 创建验证码图片 & 输出到浏览器
* @access public
**/
public function show(){
$this->create_code();
$this->draw_line();
$this->draw_word();
$this->browser();
imagedestroy($this->im);
}
}
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )