A question about the GP Library in php-php Tutorial

Source: Internet
Author: User
A question about the GP Library in php encapsulates the GD library into the class, but I don't know where the error occurred,
Please take a look at it with me. thank you!
I couldn't find the error for two days, but the picture still couldn't be displayed,
For example:

(Write a form biaodan. php first)



Codetest









(Then encapsulated a class vcode. class. php)
Class Vcode {
Private $ width; // width
Private $ height; // high
Private $ num; // quantity
Private $ code; // verification code
Private $ img; // Image resources

// Constructor, three parameters
Function _ construct ($ width, $ height, $ num ){
$ This-> width = $ width;
$ This-> height = $ height;
$ This-> num = $ num;
$ This-> code = $ this-> gocode (); // call your own method
}

// Obtain the character verification code, which is saved on the server.
Function getcode (){

Return $ this-> code;


}
// Output image
Function outimg (){
// Create a background (color, size, and Border)
$ This-> createback ();

// Output image
$ This-> printimg ();
}
// Create a background
Private function createback (){
// Create a resource
$ This-> img = imagecreatetruecolor ($ this-> width, $ htis-> height );
// Set the random color
$ Bgcolor = imagecolorallocate ($ this-> img, rand (225,255), rand (225,255), rand (225,255 ));
// Set background filling
Imagefill ($ this-> img, 0, 0, $ bgcolor );
// Draw a border
$ Bordercolor = imagecolorallocate ($ this-> img, 0, 0 );
Imagerectangle ($ this-> img, 0, 0, $ this-> width-1, $ this-> height-1, $ bordercolor );
}

// Draw words
Private function outstring (){


}

// Sets the interference element.
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 a verification code string
Private function gocode (){
$ Codes = "3456789 abcdefghijkmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY ";
$ Code = "";
For ($ I = 0; $ I <$ this-> num; $ I ++ ){
$ Code. = $ codes {rand (0, strlen ($ codes)-1 )};
}
Return $ code;
}

// Used to automatically destroy Image resources
Function _ destruct (){
Imagedestroy ($ this-> img );
}

}


(In the call class code. php)
// Enable session
Session_start ();
Include "vcode. class. php ";
// Constructor
$ Vcode = new Vcode (80, 25, 4 );
// Save the verification code in the server's own space
$ _ SESSION = $ vcode-> getcode ();
// Output the verification code Image
$ Vcode-> outimg ();


Reply to discussion (solution)

Enter code. php in the address bar of your browser to see if you can generate a verification code image.
It seems that you haven't seen the number written into the canvas.
If it is hard to write, go online and find a usable one. There are so many resources at night.

// Create a resource $ this-> img = imagecreatetruecolor ($ this-> width, $ htis-> height );

// 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.