php图形验证码生成器,PHP图片验证码生成

/**

* 验证码驱动

* @author Devil

* @version v_1.0.0

*/

class VerifyLibrary

{

private $rand_string;

private $img;

/**

* [__construct 构造方法]

*/

public function __construct()

{

/* 验证码生成 */

$this->rand_string = $this->GetRandString();

}

/**

* [GetVerify 获取当前验证码]

*/

public function GetVerify()

{

return $this->rand_string;

}

/**

* [GetVerifyImg 验证码生成]

* @return [string] [验证码]

*/

public function GetVerifyImg() {

$this->img = imagecreatetruecolor(63, 22); //创建一个画布(真色彩)

// 画背景

$back_color = imagecolorallocate($this->img, 235, 236, 237);

imagefilledrectangle($this->img,0,0,63,22,$back_color);

//加入干扰,画出多条线

$this->InterferenceLine();

//加入干扰,画出点

$this->InterferencePoint();

//将生成好的字符串写入图像

$fgcolor = imagecolorallocate($this->img, rand(0,200), rand(0,255), rand(0,255));

imagestring($this->img, 5, 5, 5, strtoupper($this->rand_string), $fgcolor);

//输出图像

header('Content-Type: image/gif');

imagegif($this->img);

//销毁图像

imagedestroy($this->img);

}

/**

* [InterferencePoint 加入干扰,画点]

*/

private function InterferencePoint()

{

for($i=0; $i<200; $i++){

$bgcolor = imagecolorallocate($this->img, rand(0,255), rand(0,255), rand(0,255)); //产生随机的颜色

imagesetpixel($this->img, rand()%90, rand()%30, $bgcolor);

}

}

/**

* [InterferenceLine 加入干扰,画出多条线]

*/

private function InterferenceLine()

{

for($i=0; $i<5; $i++)

{

$bgcolor=imagecolorallocate($this->img, rand(0,255), rand(0,255), rand(0,255)); //产生随机的颜色

imageline($this->img, rand(10,90), 0, rand(10,90), 20, $bgcolor);

}

}

/**

* [GetRandString 生成随机数值]

* @param [int] $number [随机数位数]

* @return[string] [返回小写的随机数值]

*/

private function GetRandString($number = 6)

{

$origstr = '3456789abxdefghijkmnprstuvwxy';

$verifystring = '';

$len = strlen($origstr);

for($i=0; $i

$index = mt_rand(0, $len-1);

$char = $origstr[$index];

$verifystring .= $char;

}

return $verifystring;

}

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值