国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

驗(yàn)證碼類

2019-11-14 14:43:09
字體:
供稿:網(wǎng)友

熟悉相關(guān)圖像處理函數(shù),簡單的驗(yàn)證碼類    


1
//code class 2 class ValidateCode { 3 PRivate $charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789'; //random effects 4 private $code; //code 5 private $codelen = 4 ; //code length 6 private $width = 130; //width 7 private $heigth = 50; //height 8 private $img; //image handle 9 private $font; //font file10 private $fontsize = 20; //font size11 private $fontcolor; //font color12 13 //the construct initialization14 public function __construct(){15 $this->font = ROOT_PATH.'/font/elephant.ttf';16 }17 18 //create random code from $charset19 private function createCode(){20 $_len = strlen($this->charset);21 for($i=1;$i<=$this->codelen;$i++){22 $this->code .= $this->charset[mt_rand(0,$_len)];23 }24 }25 26 //create background27 private function createBg(){28 $this->img = imagecreatetruecolor($this->width, $this->heigth);29 $_color = imagecolorallocate($this->img, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));30 imagefilledrectangle($this->img,0,0,$this->width,$this->heigth,$_color);31 }32 33 //create font34 private function createFont(){35 $_x = $this->width / $this->codelen;36 for($i=0;$i<$this->codelen;$i++){37 $this->fontcolor = imagecolorallocate($this->img, mt_rand(0,156), mt_rand(0,156), mt_rand(0,156));38 imagettftext($this->img, $this->fontsize, mt_rand(-30,30), $_x*$i+mt_rand(1,5), $this->heigth/1.4, $this->fontcolor, $this->font, $this->code[$i]);39 }40 }41 42 //create line,snowflake43 private function createLine(){44 for($i=0;$i<6;$i++){45 $_color = imagecolorallocate($this->img, mt_rand(0,156), mt_rand(0,156), mt_rand(0,156));46 imageline($this->img, mt_rand(0,$this->width), mt_rand(0, $this->heigth),mt_rand(0,$this->width), mt_rand(0, $this->heigth), $_color);47 }48 for($i=0;$i<100;$i++){49 $_color = imagecolorallocate($this->img, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));50 imagestring($this->img, mt_rand(1, 5), mt_rand(0,$this->width), mt_rand(0,$this->heigth), '*', $_color);51 }52 }53 54 //export image55 private function outPut(){56 header('Content-type:image/png');57 imagepng($this->img);58 imagedestroy($this->img);59 }60 61 //display62 public function doimg(){63 $this->createBg();64 $this->createCode();65 $this->createLine();66 $this->createFont();67 $this->outPut();68 }69 70 //get code71 public function getCode(){72 return strtolower($this->code);73 }74 75 }76

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 通辽市| 南宁市| 大洼县| 甘肃省| 和顺县| 苏尼特左旗| 万宁市| 马龙县| 梨树县| 施秉县| 伽师县| 商都县| 富民县| 交城县| 新昌县| 鸡泽县| 井陉县| 南开区| 蒙城县| 泽普县| 肥西县| 庆阳市| 衡东县| 保亭| 张家港市| 江都市| 康马县| 封丘县| 五家渠市| 石台县| 长治县| 闻喜县| 昭苏县| 台南县| 蒙阴县| 微博| 曲阜市| 乐陵市| 柳江县| 双柏县| 伊宁市|