検索
ホームページphp教程php手册中国語の英数字、カスタム フォントの PHP 検証コード コードをサポート

中国語の英数字、カスタム フォントの PHP 検証コード コードをサポート

Jun 13, 2016 pm 12:02 PM
captchaclassphp中国語コードコピーフォント手紙サポート番号コードカスタマイズ確認する

コードをコピー コードは次のとおりです:


/*
* PHP GD Lib ベースの Captcha クラス
* @author Design
* @version 1.0
* @demo
* include('captchaClass.php');
* $captchaDemo=new Captcha();
* $captchaDemo->createImage();
クラス キャプチャ{
// @検証コード画像の高さを定義します
private $height; //@検証コード画像の幅を定義します
private $width; //@検証コードの文字数を定義します
$textNum;
//@検証コードの文字内容を定義します
private $textContent; //@文字の色を定義します
//@ランダムなテキストの色を定義します
private $randFontColor;
//@フォント サイズを定義
private $fontSize; ;
//@ランダムな背景色を定義します
private $randBgColor;
//@文字言語を定義します
//@干渉点の数を定義します
private $noisePoint;
//@干渉ラインの数を定義します
private $noiseLine;
//@歪ませるかどうかを定義します
private $distortion;画像ソース
private $distortionImage;
//@境界線があるかどうかを定義します
private $showBorder;
//@検証コード画像ソースを定義します
private $image;
//@Constructor コンストラクター
public function Captcha(){
$this->gt;textNum=4;
$this->fontFamily; ='c:windowsfontsSIMYOU.ttf'; //中国語フォントを設定します。Linux ディレクトリに変更できます
$this->textLang='en';
$this->noiseLine=3;
$this->distortion=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;
}

//@Set font
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;
}

// @初期化検証コード image
public function initImage(){
if($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);
}

//@ランダムな文字を生成します
function randText($type){
$string='';
switch($type){
case 'en':
$str='ABCDEFGHJKLMNPQRSTUVWXY3456789'; =0;$itextNum;$i ){
$string=$string.' ,'.$str[mt_rand(0,29)];
}
break;
case 'cn':
for($i=0;$itextNum ;$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;$itextNum;$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;$inoisePoint;$ i ){
$pointColor=imagecolorallocate($this->image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($this->image,mt_rand(0,$this->幅),mt_rand(0,$this->高さ),$pointColor);
}

}

//@产生干扰線
public function createNoiseLine(){
for($i=0;$iノイズライン;$i ) {
$lineColor=imagecolorallocate($this->image,mt_rand(0,255),mt_rand(0,255),20);
imageline($this->image,0,mt_rand(0,$this->幅),$this->幅,mt_rand(0,$this->高さ),$lineColor);
}
}

//@扭曲文字
public functiondistortionText(){
$this->distortionImage=imagecreatetruecolor($this->width,$this- >身長);
imagefill($this->distortionImage,0,0,$this->randBgColor);
for($x=0;$xwidth;$x ){
for($y=0;$yheight;$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;
}

}
?>使用方法:

//session_start();
header("Content-type:image/png");
include('captcha5_class.php');
$captcha5=新しいキャプチャ();

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

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

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

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

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

//@设置文字体
$captcha5->setFontFamily('c:windowsfontsSTXINGKA.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();
?>

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

SublimeText3 英語版

SublimeText3 英語版

推奨: Win バージョン、コードプロンプトをサポート!

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール