This article mainly for you in detail the PHP image verification code generation code, with a certain reference value, interested in small partners can refer to
The example of this article for everyone to share a PHP package generated image verification code, for your reference, the specific content as follows
One, the code
Index: Php
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Testcode.php
<?php class testcode{//creates a Testcode private $width; Private $height; Private $str; Private $im; Private $strColor; function construct ($width, $height) {$this->width= $width; $this->height= $height; $this->str=$_get[' code '; $this->createimage (); } function CreateImage () {$this->im=imagecreate ($this->width, $this->height);//Create Canvas imagecolorallocate ( $this->im,200,200,200);//Add a color for the canvas for ($i =0; $i <4; $i + +) {//loop output four digits $this->strcolor=imagecolorallocate ($thi S->im,rand (0,100), Rand (0,100), Rand (0,100)); Imagestring ($this->im,rand (3,5), $this->width/4* $i +rand (5,10), rand (2,5), $this->str[$i], $this- Strcolor); } for ($i =0; $i <200; $i + +) {//Loop output 200 dots $this->strcolor=imagecolorallocate ($this->im,rand (0,255), Rand (0,2 ), Rand (0,255)); Imagesetpixel ($this->im,rand (0, $this->width), rand (0, $this->height), $this->strcolor); }} function Show () {//Header(' content-type:image/png ');//define output as Image type Imagepng ($this->im);//Generate Image Imagedestroy ($this->im);//Destroy image to free memory} } $image =new Testcode (80,20);//Instantiate class as Object $image->show ();//Call Function?>
ii. Results of Operation