Home >Backend Development >PHP Tutorial >A very practical PHP verification code class_PHP tutorial
A more practical PHP graphic verification code generation class, the calling method is also very simple, friends in need can refer to it.
The code is as follows
|
Copy code | ||||
class ImageCode{
private $width;//Verification code image width
private $height;//Verification code image height
private $codeNum;//The number of characters in the verification code
private $checkCode;//Verification code characters
private $image;//Verification code canvas
function __construct($width=60,$height=20,$codeNum=4){
$this->width=$width;
$this->height=$height;
$this->codeNum=$codeNum;
$this->checkCode=$this->createCheckCode();
}
function getcreateImage(){
$this->getcreateImage();
$this->outputText();
$this->setDisturbColor();
$this->outputImage();
}
function getCheckCode(){
Return $this->checkCode;
}
private function getCreateImage(){
$this->image=imagecreatetruecolor($this->width,$this->height);
$black=imagecolorallocate($this->image,255,255,255,0);
$border=imagecolorallocate($this->image,255,255,255,255);
imagefilledrectangle($this->image,0,0,$this->width-1,$this->height-1,$border);
}