I saw an image verification code on the Internet, which was very nice, but I found it a little problem. I 'd like to change it to my own taste. In many cases, if I cannot use it, it should be a font issue. The font used by the program comes with win7 and needs to be uploaded to the web directory 1. Display Effect
II. The Code is as follows:
The Code is as follows:
/*
* @ Author fy
*/
$ Imgwidth = 100; // Image Width
$ Imgheight = 40; // Image Height
$ Codelen = 4; // verification code length
$ Fontsize = 20; // font size
$ Charset = 'abcdefghkmnprstuvwxyzabcdefghkmnprstuvwxyz23456789 ';
$ Font = 'fonts/segoesc. ttf ';
$ Im = imagecreatetruecolor ($ imgwidth, $ imgheight );
$ While = imageColorAllocate ($ im, 255,255,255 );
Imagefill ($ im, $ while); // fill the image
// Obtain the string
$ Authstr = '';
$ _ Len = strlen ($ charset)-1;
For ($ I = 0; $ I <$ codelen; $ I ++ ){
$ Authstr. = $ charset [mt_rand (0, $ _ len)];
}
Session_start ();
$ _ SESSION ['scode'] = strtolower ($ authstr); // convert all to lowercase, mainly to be case insensitive
// Randomly draw a point, which has been changed to star
For ($ I = 0; $ I <$ imgwidth; $ I ++ ){
$ Randcolor = imageColorallocate ($ im, mt_rand (200,255), mt_rand (200,255), mt_rand (200,255 ));
Imagestring ($ im, mt_rand (1, 5), mt_rand (0, $ imgwidth), mt_rand (0, $ imgheight), '*', $ randcolor );
// Imagesetpixel ($ im, mt_rand (0, $ imgwidth), mt_rand (0, $ imgheight), $ randcolor );
}
// Draw lines randomly. The number of lines = the number of characters (casual)
For ($ I = 0; $ I <$ codelen; $ I ++)
{
$ Randcolor = imagecolorallocate ($ im, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imageline ($ im, 0, mt_rand (0, $ imgheight), $ imgwidth, mt_rand (0, $ imgheight), $ randcolor );
}
$ _ X = intval ($ imgwidth/$ codelen); // calculates the character distance.
$ _ Y = intval ($ imgheight * 0.7); // the position where the character is displayed on the image 70%.
For ($ I = 0; $ I
$ Randcolor = imagecolorallocate ($ im, mt_rand (0,150), mt_rand (0,150), mt_rand (0,150 ));
// Imagestring ($ im, 5, $ j, 5, $ imgstr [$ I], $ color3 );
// Imagettftext (resource $ image, float $ size, float $ angle, int $ x, int $ y, int $ color, string $ fontfile, string $ text)
Imagettftext ($ im, $ fontsize, mt_rand (-30,30), $ I * $ _ x + 3, $ _ y, $ randcolor, $ font, $ authstr [$ I]);
}
// Generate an image
Header ("content-type: image/PNG ");
ImagePNG ($ im );
ImageDestroy ($ im );