PHP generated Chinese Verification Code program

Source: Internet
Author: User
Tags rand

Today accidentally think of write verification code number plus Chinese characters, the following is the code easier to have nothing to say

Let's take a look at the effect chart first.

Isn't it good?

<?php
Header ("Content-type:image/png");//type of picture generated
$str = "One is in the discord of the main human silkworm million moments";/or you can increase yourself
$Width = 240;//Picture height
$imgHeight = 40;//Picture width
$C _img = imagecreate ($Width, $imgHeight);
$bgColor = Imagecolorallocate ($C _img,255,255,255);
$f _font = "Heiti.ttf";//You can choose a different font here
$white =imagecolorallocate ($C _img,234,185,95);
Imagearc ($C _img, 8, 170, $white);
Imagearc ($C _img, 180, 7,50, 175, $white);
Imageline ($C _img,20,20,180,30, $white);
Imageline ($C _img,20,18,170,50, $white);
Imageline ($C _img,25,50,80,50, $white);
$noise _num = 800;//of data from miscellaneous points
$line _num = number of 20;//lines
Imagecolorallocate ($C _img,0xff,0xff,0xff);
$rectangle _color=imagecolorallocate ($C _img,0xaa,0xaa,0xaa);
$noise _color=imagecolorallocate ($C _img,0x00,0x00,0x00);
$font _color=imagecolorallocate ($C _img,0x00,0x00,0x00);
$line _color=imagecolorallocate ($C _img,0x00,0x00,0x00);
for ($i =0; $i < $noise _num; $i + +) {
Imagesetpixel ($C _img,mt_rand (0, $Width), Mt_rand (0, $imgHeight), $noise _color);
}
for ($i =0; $i < $line _num; $i + +) {
Imageline ($C _img,mt_rand (0, $Width), Mt_rand (0, $imgHeight), Mt_rand (0, $Width), Mt_rand (0, $imgHeight), $line _color);
}
$randnum =rand (0,strlen ($STR)-4);
if ($randnum%2) $randnum +=1;
$str = substr ($str, $randnum, 8);
$str = Iconv ("GB2312", "UTF-8", $str). Rand (0,1000);//Conversion encoding
Imagettftext ($C _img, 0, $font _color, $f _font, $STR);
Imagepng ($C _img);
Imagedestroy ($C _img);
?>

NOTE: Reprint please explain the original www.111cn.net

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.