A question about the GP Library in php

Source: Internet
Author: User
Tags set background gocode
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 );

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.