on the internet to see a picture verification code, 挻 beautiful, but take back found, seems to have a little problem, or to their own taste it, a lot of times, if you can not use, it should be the problem of fonts. The font used by the program is Win7 and needs to be uploaded to the web directory
First, the display effect Two, the code as follows code as follows: * * @Author fy */ $imgwidth = 100; Picture width $imgheight = 40; Picture 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, 0,0, $while); Fill image //get string $authstr = '; $_len = strlen ($charset)-1; For ($i =0 $i < $codelen; $i + +) { $AUTHSTR. = $charset [Mt_rand (0,$_len)];} session_start (); $_session[' Scode ']=strtolower ($AUTHSTR);//All lowercase, mainly for case-insensitive //random drawing points, 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); //random draw line, line number = 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); Compute character Distance $_y=intval ($imgheight *0.7); The character is displayed in picture 70% for ($i =0; $i <strlen ($AUTHSTR), $i + +) { $randcolor =imagecolorallocate ($im, Mt_rand ( 0,150), Mt_rand (0,150), Mt_rand (0,150)); //imagestring ($im, 5, $j, 5, $imgstr [$i], $color 3); //Imagettftext (Resource $image, float $size, float $angle, int $x, int $y, int $color, string $fontfile, S Tring $text) imagettftext ($im, $fontsize, Mt_rand ( -30,30), $i *$_x+3,$_y, $randcolor, $font, $authstr [$i]); } //Generate Image Header ("Content-type:image/png"); Imagepng ($im); Imagedestroy ($im);