Copy CodeThe code is as follows:
Public Function Captcha () {
$font _dir = $_server ["Document_root"]. "Your_ttf_file.ttf"; Font Library
$img _w = 58; Set Picture width
$img _h = 20; Set Picture height
$font _size = 11; Font size
$angle _l =-10; Left angle
$angle _r = 10; Right angle
$code _str = "ABCDEFGHJKLMNPQRSTUVWXYZ36";
$word _len = 4; Verify number of code bits
$padding = 5; intervals between two words
$margin = 2; Left margin
$base _line = 15; Text Baseline position
$base _line_offset = 2; Baseline offset
$pixel _num = 3; Number of miscellaneous points base
$pixel _color= 8; The clutter is only $pixel _color color total number of $pixel_num* $pixel _color
$noise _font_size = 1; Clutter Font Size
$sessi//Custom session key Name
Header ("Cache-control:no-cache, must-revalidate");
Header ("Expires:mon, Jul 1997 05:00:00 GMT");
Header ("Pragma:no-cache");
Header ("Cache-control:private");
Header (' content-type:image/png ');
Session_Start ();
$word = "";
$code _str_len = strlen ($code _str)-1;
for ($i = 0; $i < $word _len; $i + +) {
$word. = $code _str[rand (0, $code _str_len)];
}
$_session [$session _key] = Strtolower ($word);
$image = Imagecreatetruecolor ($img _w, $img _h);
Imagefilledrectangle ($image, 0, 0, $img _w-1, $img _h-1, Imagecolorallocate ($image, Mt_rand (235, 255), Mt_rand (235, 255) , Mt_rand (235, 255));
Draw a noise point
for ($i = 0; $i < $pixel _color; $i + +) {
$noise _color = imagecolorallocate ($image, Mt_rand (150,225), Mt_rand (150,225), Mt_rand (150,225));
for ($j = 0; $j < $pixel _num; $j + +) {
Imagestring ($image, $noise _font_size, Mt_rand ( -10, $img _w), Mt_rand ( -10, $img _h), $code _str[mt_rand (0, $code _str_len) ], $noise _color);
}
}
Draw text
for ($i = 0; $i < $word _len; + + $i) {
$color = Imagecolorallocate ($image, Mt_rand (0, 150), Mt_rand (+), Mt_rand (50,));
Imagettftext ($image, $font _size, Mt_rand ($angle _l, $angle _r), $margin, Mt_rand ($base _line-$base _line_offset, $base _ line+ $base _line_offset), $color, $font, Mb_substr ($word, $i, 1, ' utf-8 '));
$margin + = (imagefontwidth ($font _size) + $padding);
}
Imagepng ($image);
Imagedestroy ($image);
Exit
}
The above describes the custom Hero Survival 1.87 php High custom security code codes, including the Custom Hero Survival 1.87 aspects of the content, I hope to be interested in PHP tutorial friends helpful.