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