\ (^o^)/~
Now online more and more inseparable from the verification code, do not know the small partners know that the use of PHP GD Library can generate verification code, Σ (⊙▽⊙ "a ...
Let's start by introducing several functions that need to be used.
1.imagesetpixel ()
This function can be used to draw pixel points, in the verification code, we call "noise", is simply an artifact. I don't know if my little buddy thinks about it. The point on the verification code is generated using this function.
2.str_shuffle ()
Using this scrambled string, and then using substr () to intercept the given number of bits, you can generate a random string.
Instance:
1<?PHP2 3$img = Imagecreatetruecolor ( -, -);4$black = Imagecolorallocate ($img,0x00,0x00,0x00);5$green = Imagecolorallocate ($img,0x00,0xFF,0x00);6$white = Imagecolorallocate ($img,0xFF,0xFF,0xFF);7Imagefill ($img,0,0, $white);8 //generate a random verification code9$code = Make (5);TenImagestring ($img,5,Ten,Ten, $code, $black); One //add noise interference. A for($i =0; $i < -; $i + +) { -Imagesetpixel ($img, Rand (0, -), Rand (0, -), $black); -Imagesetpixel ($img, Rand (0, -), Rand (0, -), $green); the } - //Join line Interference - for($n =0; $n <=1; $n + +) { -Imageline ($img,0, Rand (0, +), -, Rand (0, +), $black); +Imageline ($img,0, Rand (0, +), -, Rand (0, +), $white); - } + //Output Verification Code AHeader"Content-type:image/png"); at imagepng ($img); - //Destroying pictures - Imagedestroy ($img); - //the function of producing random verification code - function make ($length) - { in$code ='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; - returnsubstr (Str_shuffle ($code),0, $length); to}
Effect:
PHP graphics Image processing generation verification code