PHP generates a digital letter verification code picture
-
- Header (' content-type:image/png ');
- $image =imagecreatetruecolor (100, 30);
- $color =imagecolorallocate ($image, 255, 255, 255);
- Imagefill ($image, $color);
- Contains only numbers
- for ($i =0; $i <4; $i + +) {
- $font = 6;
- $x =rand (5,10) + $i *100/4;
- $y =rand (8, 15);
- $string =rand (0, 9);
- $color =imagecolorallocate ($image, Rand (0,120), Rand (0,120), Rand (0,120));
- Imagestring ($image, $font, $x, $y, $string, $color);
- // }
- containing numbers and letters.
- for ($i =0; $i <4; $i + +) {
- $fontSize = 6;
- $x =rand (5,10) + $i *100/4;
- $y =rand (5, 15);
- $data = ' abcdefghijklmnopqrstuvwxyz123456789 ';
- $string =substr ($data, rand (0, strlen ($data)), 1);
- $color =imagecolorallocate ($image, Rand (0,120), Rand (0,120), Rand (0,120));
- Imagestring ($image, $fontSize, $x, $y, $string, $color);
- }
- Interference point Element
- for ($i =0; $i <200; $i + +) {
- $pointColor =imagecolorallocate ($image, rand (255), Rand (255), rand (100, 255));
- Imagesetpixel ($image, rand (0, +), rand (0,), $pointColor);
- }
- Interference line Elements
- for ($i =0; $i <2; $i + +) {
- $linePoint =imagecolorallocate ($image, rand (255), Rand (255), Rand (150, 255));
- Imageline ($image, rand (+), Rand (TEN), Rand (80,90), rand (+), $linePoint);
- }
- Imagepng ($image);
- Imagedestroy ($image);
- ?>
Copy CodeThe above mentioned is the whole content of this article, I hope you can like. |