类

王朝学院·作者佚名  2016-08-27  
宽屏版  字体: 小 | 中 | 大 | 超大  

熟悉相关图像处理函数,简单的验证码类

1//code class2classValidateCode {3PRivate$charset= 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789';//random effects4private$code;//code5private$codelen= 4 ;//code length6private$width= 130;//width7private$heigth= 50;//height8private$img;//image handle9private$font;//font file10private$fontsize= 20;//font size11private$fontcolor;//font color1213//the construct initialization14publicfunction__construct(){15$this->font = ROOT_PATH.'/font/elephant.ttf';16}1718//create random code from $charset19privatefunctioncreateCode(){20$_len=strlen($this->charset);21for($i=1;$i<=$this->codelen;$i++){22$this->code .=$this->charset[mt_rand(0,$_len)];23}24}2526//create background27privatefunctioncreateBg(){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));30imagefilledrectangle($this->img,0,0,$this->width,$this->heigth,$_color);31}3233//create font34privatefunctioncreateFont(){35$_x=$this->width /$this->codelen;36for($i=0;$i<$this->codelen;$i++){37$this->fontcolor = imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));38imagettftext($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}4142//create line,snowflake43privatefunctioncreateLine(){44for($i=0;$i<6;$i++){45$_color= imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));46imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->heigth),mt_rand(0,$this->width),mt_rand(0,$this->heigth),$_color);47}48for($i=0;$i<100;$i++){49$_color= imagecolorallocate($this->img,mt_rand(157,255),mt_rand(157,255),mt_rand(157,255));50imagestring($this->img,mt_rand(1, 5),mt_rand(0,$this->width),mt_rand(0,$this->heigth), '*',$_color);51}52}5354//export image55privatefunctionoutPut(){56header('Content-type:image/png');57imagepng($this->img);58imagedestroy($this->img);59}6061//display62publicfunctiondoimg(){63$this->createBg();64$this->createCode();65$this->createLine();66$this->createFont();67$this->outPut();68}6970//get code71publicfunctiongetCode(){72returnstrtolower($this->code);73}7475}76

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有