A question about the GP library in PHP

Source: Internet
Author: User
Ask for a question about the GP library inside PHP
The GD library is encapsulated into the class, but I don't know where it went wrong,
Please take a look at the time, the younger brother is grateful, thank you
Looking for two days did not find there is wrong, the picture is still not show,
Such as:

(I wrote a form biaodan.php first)



<title>Codetest</title>









(then encapsulates a class vcode.class.php)
Class vcode{
Private $width; Wide
private $height;//High
Private $num; Number
private $code;//Verification Code
Private $img; Resources for images

Construction method, three parameters
function __construct ($width, $height, $num) {
$this->width= $width;
$this->height= $height;
$this->num= $num;
$this->code= $this->gocode ();//Call your own method
}

Gets the verification code for the character to be saved in the server
function GetCode () {

return $this->code;


}
Output image
function outimg () {
Create background (color, size, border)
$this->createback ();

Output image
$this->printimg ();
}
Create a background
Private Function Createback () {
Create a resource
$this->img=imagecreatetruecolor ($this->width, $htis->height);
Set Random Colors
$bgcolor =imagecolorallocate ($this->img,rand (225,255), Rand (225,255), Rand (225,255));
Set Background fill
Imagefill ($this->img,0,0, $bgcolor);
Draw Border
$bordercolor =imagecolorallocate ($this->img,0,0,0);
Imagerectangle ($this->img,0,0, $this->width-1, $this->height-1, $bordercolor);
}

Stooped
Private Function outstring () {


}

Setting interference elements
Private Function Grcode () {

}

Output image
Private Function printimg () {
if (Imagetypes () & Img_gif) {
Header ("Content-type:image/gif");
Imagegif ($this->img);
}else if (Imagetypes () & img_jpg) {
Header ("Content-type:image/jpeg");
Imagejpeg ($this->img);
}else if (Imagetypes () & Img_png) {
Header ("Content-type:image/png");
Imagepng ($this->img);
}else{
Die ("No image, support in this PHP server");
}
}

Generate Authenticode String
Private Function Gocode () {
$codes = "3456789abcdefghijkmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY";
$code = "";
for ($i =0; $i < $this->num; $i +) {
$code. = $codes {rand (0,strlen ($codes)-1)};
}
return $code;
}

For automatic destruction of image resources
function __destruct () {
Imagedestroy ($this->img);
}

}


(In call class code.php)
Open session
Session_Start ();
Include "vcode.class.php";
Construction method
$vcode = new Vcode (80,25,4);
Save a copy of the validation to the server's own space
$_session= $vcode->getcode ();
The Captcha picture output
$vcode->outimg ();
------to solve the idea----------------------
Create a resource
$this->img=imagecreatetruecolor ($this->width,$ Htis->height);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.