亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 2259 | 回復(fù): 1
打印 上一主題 下一主題

支持中文字母數(shù)字、自定義字體php驗(yàn)證碼程序 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2012-03-02 17:18 |只看該作者 |倒序?yàn)g覽
支持中文字母數(shù)字、自定義字體php驗(yàn)證碼程序
  1. <?php
  2. /*
  3. * Captcha Class base on PHP GD Lib
  4. * @author Design
  5. * @version 1.0
  6. * @copyright http://www.hzhuti.com/nokia/n97/ 2010
  7. * @demo
  8. * include('captchaClass.php');
  9. * $captchaDemo=new Captcha();
  10. * $captchaDemo->createImage();
  11. */
  12. class Captcha{
  13. //@定義驗(yàn)證碼圖片高度
  14. private $height;
  15. //@定義驗(yàn)證碼圖片寬度
  16. private $width;
  17. //@定義驗(yàn)證碼字符個(gè)數(shù)
  18. private $textNum;
  19. //@定義驗(yàn)證碼字符內(nèi)容
  20. private $textContent;
  21. //@定義字符顏色
  22. private $fontColor;
  23. //@定義隨機(jī)出的文字顏色
  24. private $randFontColor;
  25. //@定義字體大小
  26. private $fontSize;
  27. //@定義字體
  28. private $fontFamily;
  29. //@定義背景顏色
  30. private $bgColor;
  31. //@定義隨機(jī)出的背景顏色
  32. private $randBgColor;
  33. //@定義字符語(yǔ)言
  34. private $textLang;
  35. //@定義干擾點(diǎn)數(shù)量
  36. private $noisePoint;
  37. //@定義干擾線數(shù)量
  38. private $noiseLine;
  39. //@定義是否扭曲
  40. private $distortion;
  41. //@定義扭曲圖片源
  42. private $distortionImage;
  43. //@定義是否有邊框
  44. private $showBorder;
  45. //@定義驗(yàn)證碼圖片源
  46. private $image;

  47. //@Constructor 構(gòu)造函數(shù)
  48. public function Captcha(){
  49. $this->textNum=4;
  50. $this->fontSize=16;
  51. $this->fontFamily='c:\windows\fontsSIMYOU.ttf';//設(shè)置中文字體,可以改成linux的目錄
  52. $this->textLang='en';
  53. $this->noisePoint=30;
  54. $this->noiseLine=3;
  55. $this->distortion=false;
  56. $this->showBorder=false;
  57. }



  58. //@設(shè)置圖片寬度
  59. public function setWidth($w){
  60. $this->width=$w;
  61. }

  62. //@設(shè)置圖片高度
  63. public function setHeight($h){
  64. $this->height=$h;
  65. }

  66. //@設(shè)置字符個(gè)數(shù)
  67. public function setTextNumber($textN){
  68. $this->textNum=$textN;
  69. }

  70. //@設(shè)置字符顏色
  71. public function setFontColor($fc){
  72. $this->fontColor=sscanf($fc,'#%2x%2x%2x');
  73. }

  74. //@設(shè)置字號(hào)
  75. public function setFontSize($n){
  76. $this->fontSize=$n;
  77. }

  78. //@設(shè)置字體
  79. public function setFontFamily($ffUrl){
  80. $this->fontFamily=$ffUrl;
  81. }

  82. //@設(shè)置字符語(yǔ)言
  83. public function setTextLang($lang){
  84. $this->textLang=$lang;
  85. }

  86. //@設(shè)置圖片背景
  87. public function setBgColor($bc){
  88. $this->bgColor=sscanf($bc,'#%2x%2x%2x');
  89. }

  90. //@設(shè)置干擾點(diǎn)數(shù)量
  91. public function setNoisePoint($n){
  92. $this->noisePoint=$n;
  93. }

  94. //@設(shè)置干擾線數(shù)量
  95. public function setNoiseLine($n){
  96. $this->noiseLine=$n;
  97. }

  98. //@設(shè)置是否扭曲
  99. public function setDistortion($b){
  100. $this->distortion=$b;
  101. }

  102. //@設(shè)置是否顯示邊框
  103. public function setShowBorder($border){
  104. $this->showBorder=$border;
  105. }

  106. //@初始化驗(yàn)證碼圖片
  107. public function initImage(){
  108. if(empty($this->width)){$this->width=floor($this->fontSize*1.3)*$this->textNum+10;}
  109. if(empty($this->height)){$this->height=$this->fontSize*2;}
  110. $this->image=imagecreatetruecolor($this->width,$this->height);
  111. if(empty($this->bgColor)){
  112. $this->randBgColor=imagecolorallocate($this->image,mt_rand(100,255),mt_rand(100,255),mt_rand(100,255));
  113. }else{
  114. $this->randBgColor=imagecolorallocate($this->image,$this->bgColor[0],$this->bgColor[1],$this->bgColor[2]);
  115. }
  116. imagefill($this->image,0,0,$this->randBgColor);
  117. }

  118. //@產(chǎn)生隨機(jī)字符
  119. public function randText($type){
  120. $string='';
  121. switch($type){
  122. case 'en':
  123. $str='ABCDEFGHJKLMNPQRSTUVWXY3456789';
  124. for($i=0;$i<$this->textNum;$i++){
  125. $string=$string.','.$str[mt_rand(0,29)];
  126. }
  127. break;
  128. case 'cn':
  129. for($i=0;$i<$this->textNum;$i++) {
  130. $string=$string.','.chr(rand(0xB0,0xCC)).chr(rand(0xA1,0xBB));
  131. }
  132. $string=iconv('GB2312','UTF-8',$string); //轉(zhuǎn)換編碼到utf8
  133. break;
  134. }
  135. return substr($string,1);
  136. }

  137. //@輸出文字到驗(yàn)證碼
  138. public function createText(){
  139. $textArray=explode(',',$this->randText($this->textLang));
  140. $this->textContent=join('',$textArray);
  141. if(empty($this->fontColor)){
  142. $this->randFontColor=imagecolorallocate($this->image,mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
  143. }else{
  144. $this->randFontColor=imagecolorallocate($this->image,$this->fontColor[0],$this->fontColor[1],$this->fontColor[2]);
  145. }
  146. for($i=0;$i<$this->textNum;$i++){
  147. $angle=mt_rand(-1,1)*mt_rand(1,20);
  148. imagettftext($this->image,$this->fontSize,$angle,5+$i*floor($this->fontSize*1.3),floor($this->height*0.75),$this->randFontColor,$this->fontFamily,$textArray[$i]);
  149. }
  150. }

  151. //@生成干擾點(diǎn)
  152. public function createNoisePoint(){
  153. for($i=0;$i<$this->noisePoint;$i++){
  154. $pointColor=imagecolorallocate($this->image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  155. imagesetpixel($this->image,mt_rand(0,$this->width),mt_rand(0,$this->height),$pointColor);
  156. }

  157. }

  158. //@產(chǎn)生干擾線
  159. public function createNoiseLine(){
  160. for($i=0;$i<$this->noiseLine;$i++) {
  161. $lineColor=imagecolorallocate($this->image,mt_rand(0,255),mt_rand(0,255),20);
  162. imageline($this->image,0,mt_rand(0,$this->width),$this->width,mt_rand(0,$this->height),$lineColor);
  163. }
  164. }

  165. //@扭曲文字
  166. public function distortionText(){
  167. $this->distortionImage=imagecreatetruecolor($this->width,$this->height);
  168. imagefill($this->distortionImage,0,0,$this->randBgColor);
  169. for($x=0;$x<$this->width;$x++){
  170. for($y=0;$y<$this->height;$y++){
  171. $rgbColor=imagecolorat($this->image,$x,$y);
  172. imagesetpixel($this->distortionImage,(int)($x+sin($y/$this->height*2*M_PI-M_PI*0.5)*3),$y,$rgbColor);
  173. }
  174. }
  175. $this->image=$this->distortionImage;
  176. }

  177. //@生成驗(yàn)證碼圖片
  178. public function createImage(){
  179. $this->initImage(); //創(chuàng)建基本圖片
  180. $this->createText(); //輸出驗(yàn)證碼字符
  181. if($this->distortion){$this->distortionText();} //扭曲文字
  182. $this->createNoisePoint(); //產(chǎn)生干擾點(diǎn)
  183. $this->createNoiseLine(); //產(chǎn)生干擾線
  184. if($this->showBorder){imagerectangle($this->image,0,0,$this->width-1,$this->height-1,$this->randFontColor);} //添加邊框
  185. imagepng($this->image);
  186. imagedestroy($this->image);
  187. if($this->distortion){imagedestroy($this->$distortionImage);}
  188. return $this->textContent;
  189. }

  190. }
  191. ?>使用方法:

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

  197. //@設(shè)置驗(yàn)證碼寬度
  198. //$captcha5->setWidth(200);

  199. //@設(shè)置驗(yàn)證碼高度
  200. //$captcha5->setHeight(50);

  201. //@設(shè)置字符個(gè)數(shù)
  202. $captcha5->setTextNumber(5);

  203. //@設(shè)置字符顏色
  204. //$captcha5->setFontColor('#ff9900');

  205. //@設(shè)置字號(hào)大小
  206. //$captcha5->setFontSize(25);

  207. //@設(shè)置字體
  208. $captcha5->setFontFamily('c:\windows\fonts\STXINGKA.TTF');

  209. //@設(shè)置語(yǔ)言
  210. $captcha5->setTextLang('cn');

  211. //@設(shè)置背景顏色
  212. //$captcha5->setBgColor('#000000');

  213. //@設(shè)置干擾點(diǎn)數(shù)量
  214. //$captcha5->setNoisePoint(600);

  215. //@設(shè)置干擾線數(shù)量
  216. //$captcha5->setNoiseLine(10);

  217. //@設(shè)置是否扭曲
  218. //$captcha5->setDistortion(true);

  219. //@設(shè)置是否顯示邊框
  220. $captcha5->setShowBorder(true);

  221. //輸出驗(yàn)證碼
  222. $code=$captcha5->createImage();
  223. //$_SESSION['captchaCode']['content']=$code;
  224. //$_SESSION['captchaCode']['time']=microtime();
  225. ?>
復(fù)制代碼

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2012-03-02 17:18 |只看該作者
謝謝分享
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP