无为清净楼资源网 Design By www.qnjia.com
复制代码 代码如下:
<?php
/*
* Captcha Class base on PHP GD Lib
* @author Design
* @version 1.0
* @demo
* include('captchaClass.php');
* $captchaDemo=new Captcha();
* $captchaDemo->createImage();
*/
class Captcha{
//@定义验证码图片高度
private $height;
//@定义验证码图片宽度
private $width;
//@定义验证码字符个数
private $textNum;
//@定义验证码字符内容
private $textContent;
//@定义字符颜色
private $fontColor;
//@定义随机出的文字颜色
private $randFontColor;
//@定义字体大小
private $fontSize;
//@定义字体
private $fontFamily;
//@定义背景颜色
private $bgColor;
//@定义随机出的背景颜色
private $randBgColor;
//@定义字符语言
private $textLang;
//@定义干扰点数量
private $noisePoint;
//@定义干扰线数量
private $noiseLine;
//@定义是否扭曲
private $distortion;
//@定义扭曲图片源
private $distortionImage;
//@定义是否有边框
private $showBorder;
//@定义验证码图片源
private $image;

//@Constructor 构造函数
public function Captcha(){
$this->textNum=4;
$this->fontSize=16;
$this->fontFamily='c:\windows\fontsSIMYOU.ttf';//设置中文字体,可以改成linux的目录
$this->textLang='en';
$this->noisePoint=30;
$this->noiseLine=3;
$this->distortion=false;
$this->showBorder=false;
}



//@设置图片宽度
public function setWidth($w){
$this->width=$w;
}

//@设置图片高度
public function setHeight($h){
$this->height=$h;
}

//@设置字符个数
public function setTextNumber($textN){
$this->textNum=$textN;
}

//@设置字符颜色
public function setFontColor($fc){
$this->fontColor=sscanf($fc,'#%2x%2x%2x');
}

//@设置字号
public function setFontSize($n){
$this->fontSize=$n;
}

//@设置字体
public function setFontFamily($ffUrl){
$this->fontFamily=$ffUrl;
}

//@设置字符语言
public function setTextLang($lang){
$this->textLang=$lang;
}

//@设置图片背景
public function setBgColor($bc){
$this->bgColor=sscanf($bc,'#%2x%2x%2x');
}

//@设置干扰点数量
public function setNoisePoint($n){
$this->noisePoint=$n;
}

//@设置干扰线数量
public function setNoiseLine($n){
$this->noiseLine=$n;
}

//@设置是否扭曲
public function setDistortion($b){
$this->distortion=$b;
}

//@设置是否显示边框
public function setShowBorder($border){
$this->showBorder=$border;
}

//@初始化验证码图片
public function initImage(){
if(empty($this->width)){$this->width=floor($this->fontSize*1.3)*$this->textNum+10;}
if(empty($this->height)){$this->height=$this->fontSize*2;}
$this->image=imagecreatetruecolor($this->width,$this->height);
if(empty($this->bgColor)){
$this->randBgColor=imagecolorallocate($this->image,mt_rand(100,255),mt_rand(100,255),mt_rand(100,255));
}else{
$this->randBgColor=imagecolorallocate($this->image,$this->bgColor[0],$this->bgColor[1],$this->bgColor[2]);
}
imagefill($this->image,0,0,$this->randBgColor);
}

//@产生随机字符
public function randText($type){
$string='';
switch($type){
case 'en':
$str='ABCDEFGHJKLMNPQRSTUVWXY3456789';
for($i=0;$i<$this->textNum;$i++){
$string=$string.','.$str[mt_rand(0,29)];
}
break;
case 'cn':
for($i=0;$i<$this->textNum;$i++) {
$string=$string.','.chr(rand(0xB0,0xCC)).chr(rand(0xA1,0xBB));
}
$string=iconv('GB2312','UTF-8',$string); //转换编码到utf8
break;
}
return substr($string,1);
}

//@输出文字到验证码
public function createText(){
$textArray=explode(',',$this->randText($this->textLang));
$this->textContent=join('',$textArray);
if(empty($this->fontColor)){
$this->randFontColor=imagecolorallocate($this->image,mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
}else{
$this->randFontColor=imagecolorallocate($this->image,$this->fontColor[0],$this->fontColor[1],$this->fontColor[2]);
}
for($i=0;$i<$this->textNum;$i++){
$angle=mt_rand(-1,1)*mt_rand(1,20);
imagettftext($this->image,$this->fontSize,$angle,5+$i*floor($this->fontSize*1.3),floor($this->height*0.75),$this->randFontColor,$this->fontFamily,$textArray[$i]);
}
}

//@生成干扰点
public function createNoisePoint(){
for($i=0;$i<$this->noisePoint;$i++){
$pointColor=imagecolorallocate($this->image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($this->image,mt_rand(0,$this->width),mt_rand(0,$this->height),$pointColor);
}

}

//@产生干扰线
public function createNoiseLine(){
for($i=0;$i<$this->noiseLine;$i++) {
$lineColor=imagecolorallocate($this->image,mt_rand(0,255),mt_rand(0,255),20);
imageline($this->image,0,mt_rand(0,$this->width),$this->width,mt_rand(0,$this->height),$lineColor);
}
}

//@扭曲文字
public function distortionText(){
$this->distortionImage=imagecreatetruecolor($this->width,$this->height);
imagefill($this->distortionImage,0,0,$this->randBgColor);
for($x=0;$x<$this->width;$x++){
for($y=0;$y<$this->height;$y++){
$rgbColor=imagecolorat($this->image,$x,$y);
imagesetpixel($this->distortionImage,(int)($x+sin($y/$this->height*2*M_PI-M_PI*0.5)*3),$y,$rgbColor);
}
}
$this->image=$this->distortionImage;
}

//@生成验证码图片
public function createImage(){
$this->initImage(); //创建基本图片
$this->createText(); //输出验证码字符
if($this->distortion){$this->distortionText();} //扭曲文字
$this->createNoisePoint(); //产生干扰点
$this->createNoiseLine(); //产生干扰线
if($this->showBorder){imagerectangle($this->image,0,0,$this->width-1,$this->height-1,$this->randFontColor);} //添加边框
imagepng($this->image);
imagedestroy($this->image);
if($this->distortion){imagedestroy($this->$distortionImage);}
return $this->textContent;
}

}
?>使用方法:

<?php
//session_start();
header("Content-type:image/png");
include('captcha5_class.php');
$captcha5=new Captcha();

//@设置验证码宽度
//$captcha5->setWidth(200);

//@设置验证码高度
//$captcha5->setHeight(50);

//@设置字符个数
$captcha5->setTextNumber(5);

//@设置字符颜色
//$captcha5->setFontColor('#ff9900');

//@设置字号大小
//$captcha5->setFontSize(25);

//@设置字体
$captcha5->setFontFamily('c:\windows\fonts\STXINGKA.TTF');

//@设置语言
$captcha5->setTextLang('cn');

//@设置背景颜色
//$captcha5->setBgColor('#000000');

//@设置干扰点数量
//$captcha5->setNoisePoint(600);

//@设置干扰线数量
//$captcha5->setNoiseLine(10);

//@设置是否扭曲
//$captcha5->setDistortion(true);

//@设置是否显示边框
$captcha5->setShowBorder(true);

//输出验证码
$code=$captcha5->createImage();
//$_SESSION['captchaCode']['content']=$code;
//$_SESSION['captchaCode']['time']=microtime();
?>

标签:
php验证码

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。