加减 验证码
2015-08-11 17:45
113 查看
调用 // 注用TP时, 1.ttf放在根目录下 1.tff为yahoo字体
外部类
include "ImageCode.class.php"; $show = new \ImageCode(); $show->show(130, 35, '1.ttf', 'code');
外部类
<?php /*图片验证码文件,加减计算方式*/ class ImageCode{ private $Jiashu = 0; //加数或者减数 private $JianShu = 0; //被加数或者被减数 private $YunSuan = ''; //运算符 private $DeShu = 0; //得数 private $String = ''; //字符串样式 private $Img; //图片对象 private $Width = 100; //图片宽度 private $Height = 50; //图片高度 private $Ttf = '1.ttf';//字体文件 private $Session = 'code'; //Session变量 private function JiaShu(){ header('Content-type:image/png'); $this -> Jiashu = rand(1, 10); $this -> JianShu = rand(1, 10); $this -> YunSuan= $this -> Jiashu > $this -> JianShu ? '-' : '+'; $this -> DeShu = $this -> Jiashu > $this -> JianShu ? $this -> Jiashu - $this -> JianShu : $this -> Jiashu + $this -> JianShu; } public function Show( $W = 100, $H = 50, $T = '1.ttf', $Code = 'code' ){ $this -> JiaShu(); $this -> String = $this -> Jiashu . $this -> YunSuan . $this -> JianShu . '= ? '; $this -> Width = $W; $this -> Height = $H; $this -> Ttf = $T; $this -> Session= $Code; session_start(); $_SESSION[$this -> Session] = $this -> DeShu; $this -> Images(); } private function Images(){ $this -> Img = imagecreate($this -> Width, $this -> Height); $background_color = imagecolorallocate ($this -> Img, 255, 255, 255); imagecolortransparent($this -> Img, $background_color); imagettftext($this -> Img, 14, 0, 1, 20, imagecolorallocate ($this -> Img, 0, 0, 0), $this -> Ttf, $this -> String ); $this -> EchoImages(); } private function EchoImages(){ imagepng($this -> Img); imagedestroy($this -> Img); } }
相关文章推荐
- 关于xloader和uboot的几个初级问题
- hdu 1247 Hat’s Words
- 喵哈哈的日常选数问题
- 28-反射机制-06-反射机制(获取Class中的方法)
- 无线网
- 智渔课堂官方免费教程十九:Java常用类之String类
- Spring自定义@Qualifier
- [IOS开发]搜索用谓词NSPredicate
- 28-反射机制-05-反射机制(获取Class中的字段)
- I学霸官方免费教程十九:Java常用类之String类
- NOIP2014提高组 寻找道路
- cocosdx里面A*算法的实现#ifndef __CAT_SPRITE_H__ #define __CAT_SPRITE_H__ #include "HelloWorldScene.h" #incl
- android WebView总结
- java要在命令行运行eclipse的项目的方法
- 28-反射机制-04-反射机制(获取Class中的构造函数)
- 源码 、补码、 反码的详解(转载)
- Truck History POJ 1789【Kruscal算法 || Prim】
- IP协议解读(二)
- 使用Nginx反向代理实现负载均衡
- python 中文异常问题记录