Copy codeThe Code is as follows: <? Php
Class code
{
Var $ width = 160; // The Image width
Var $ hight = 40; // The Image Height
Var $ image;
Var $ red = 223; // The RGB color of the image
Var $ green= 225; // red
Var $ blue = 227; // green
Var $ pix = 227; // blue
Var $ pixcolor; // color;
Var $ pixred= 242; // red
Var $ pixgreen= 168; // green
Var $ pixblue = 162; // blue
Var $ txt = null; // Verification Code text
Var $ txtcode = null;
Var $ txtsub = null;
Var $ pixnum = 300; // Number of vertices
Var $ I = 0;
Var $ widthpx = 0;
Var $ highty = 0;
Var $ txreg = 50;
Var $ txtgreen = 30;
Function createimage () // create a graph and fill in the color
{
$ This-> image = imagecreate ($ this-> width, $ this-> hight );
$ This-> color = imagecolorallocate ($ this-> image, $ this-> red, $ this-> green, $ this-> blue );
Return imagefill ($ this-> image, 0, 0, $ this-> color );
}
Function createpix () // interference factor
{
For ($ this-> I = 1; $ this-> I <$ this-> pixnum; $ this-> I ++)
{
$ This-> widthpx = rand (0, $ this-> width );
$ This-> highty = rand (0, $ this-> hight );
$ This-> pixcolor = imagecolorallocate ($ this-> image, $ this-> pixred, $ this-> pixgreen, $ this-> pixblue );
Imagesetpixel ($ this-> image, $ this-> widthpx, $ this-> highty, $ this-> pixcolor );
}
}
Function gettxt () // create the verification code text
{
$ This-> txt = array ("I", "love", "you", "Ye", "just", "Hui", "Ming", "Fa ", "True", "yes", "very", "think", "no", "Zhi", "to", "yes", "what", "what ", "just", "yes", "forget", "no", "no", "you", "also", "Xu", "Shang", "", "owe", "money ");
For ($ this-> I = 0; $ this-> I <6; $ this-> I ++)
{
$ This-> sub = $ this-> txt [rand (0, 29)];
$ This-> txtcode. = $ this-> sub;
}
$ This-> txtcode = iconv ("GB2312", "UTF-8", $ this-> txtcode );
$ _ SESSION ["code"] = $ this-> txtcode; // generated verification ID
}
Function createstring () // create a verification code Image
{
Imagettftext ($ this-> image, 20, 5, 0, 40, $ this-> pixcolor, "C: \ WINDOWS \ Fonts \ simsun. ttc", $ this-> txtcode );
Header ("content-type: image/png ");
Return imagepng ($ this-> image );
Imagedestroy ($ this-> image );
}
Function getcodeimage () // obtain the verification code Image
{
$ This-> createimage ();
$ This-> gettxt ();
$ This-> createpix ();
$ This-> createstring ();
}
}
?>
<? Php
Session_start ();
$ Text = new code;
$ Text-> createimage ();
$ Text-> gettxt ();
$ Text-> createpix ();
$ Text-> createstring ();
?>