A beautiful PHP picture verification code example

Source: Internet
Author: User

  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);

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.