Copy Code code as follows:
<?php
/* Picture Verification code file, add and subtract calculation mode * *
Class imagecode{
Private $Jiashu = 0; Addends or meiosis
Private $JianShu = 0; Summand or Bing.
Private $YunSuan = '; Operator
Private $DeShu = 0; Count
Private $String = '; String style
Private $Img; Picture objects
Private $Width = 100; Picture width
Private $Height = 50; Picture height
Private $TTF = ' num.ttf ';//font file
Private $Session = ' code '; Session variable
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 = +, $H =, $T = ' Num.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, 0, 1, imagecolorallocate ($this-> img, 0, 0, 0), $this-> Ttf, $this-> St Ring);
$this-> echoimages ();
}
Private Function Echoimages () {
Imagepng ($this-> Img);
Imagedestroy ($this-> Img);
}
}
$ImageCode = new Imagecode;
$ImageCode-> Show (130, the ' Num.ttf ', ' Code ');