Ask for a question about the GP Library in php to encapsulate the GD library into the class, but I don't know what went wrong there. please take a look at it with me. I am very grateful to you, younger brother, thank you for failing to find it for two days. the picture still cannot be displayed, for example: (write a form biaodan first. php) & lt ;! DOCTYPE & nbsp; HTML & gt; & lt; html & gt; & nbsp; & lt; head & gt; ask for a question about the GP Library in php
Encapsulated 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 ();
------ Solution ----------------------
// Create a resource
$ This-> img = imagecreatetruecolor ($ this-> width, $ htis-> height );