/**
* Image Verification code file, add and subtract calculation method
*/
Class Imagecode {
Private $jiashu = 0;//addend or meiosis
Private $jianshu = 0;//Summand or minuend
Private $yunsuan = ';//Operator
Private $deshu = 0;//
Private $string = ';//String style
Private $img; Picture Object
Private $width = 100;//picture width
Private $height = 50;//picture height
Private $ttf = ' Arial.ttf '; Font files
Private $session = ' code ';//session variable
Private Function Jiashu () {
Header (' content-type:image/png ');
Header ("Content-type:image/jpeg");
$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 = $h =50, $t = ' Arial.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);//Export the image to the browser in PNG format
Imagedestroy ($this->img);//Destroy image
}
}
$ImageCode = new Imagecode;
$ImageCode->show (130,35, ' Arial.ttf ', ' Code ');
Image Verification code file, addition and subtraction calculation method