|
<?php
if (!isset ($_session)) {//To determine whether the session is open
Session_Start (); Open on the session
}
$width = 70; width of cloth painting
$height = 25; Cloth painting Height
$length =4;//Verification Code length
$code =getcode ($length); Get a random string
$_session[' verfycode ' = $code;
$img =imagecreate ($width, $height);
$bgcolor =imagecolorallocate ($img, 240,240,240);
$rectangelcolor =imagecolorallocate ($img, 150,150,150);
Imagerectangle ($img, 1,1, $width-1, $height-1, $rectangelcolor);//Draw Border
for ($i =0; $i < $length; $i + +) {//looping writing
$codecolor =imagecolorallocate ($img, Mt_rand (50,200), Mt_rand (50,128), Mt_rand (50,200));
$angle =rand ( -20,20);
$charx = $i *15+8;
$chary = ($height +14)/2+rand ( -1,1);
Imagettftext ($img, $angle, $charx, $chary, $codecolor, ' C:windowsfontssimkai.ttf ',
$code [$i]);
}
For ($i =0 $i <20; $i + +) {//Looping line drawing
$linecolor =imagecolorallocate ($img, Mt_rand (0,250), Mt_rand (0,250), Mt_rand (0,250));
$linex =mt_rand (1, $width-1);
$liney =mt_rand (1, $height-1);
Imageline ($img, $linex, $liney, $linex +mt_rand (0,4)-2, $liney +mt_rand (0,4)-2, $linecolor);
}
For ($i =0 $i <100; $i + +) {//Loop point
$pointcolor =imagecolorallocate ($img, Mt_rand (0,250), Mt_rand (0,250), Mt_rand (0,250));
Imagesetpixel ($img, Mt_rand (1, $width-1), Mt_rand (1, $height-1), $pointcolor);
}
function GetCode ($length) {//Generate PHP random number
$pattern = ' 1234567890ABCDEFGHIJKLOMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ';//character Fu Chi
for ($i =0; $i < $length; $i + +) {
$key. = $pattern {Mt_rand (0,35)};
}
return $key;
}
Ob_clean ();
Header (' content-type:image/png ');
Imagepng ($IMG);
?>
|