Php generates a verification code Image of numbers and letters
-
- Header ('content-Type: image/png ');
- $ Image = imagecreatetruecolor (100, 30 );
- $ Color = imagecolorallocate ($ image, 255,255,255 );
- Imagefill ($ image, 20, 20, $ color );
- // Only contains 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 );
- //}
- // Contains numbers and letters
- For ($ I = 0; $ I <4; $ I ++ ){
- $ FontSize = 6;
- $ X = rand (100/4) + $ I;
- $ 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 I <200; $ I ++ ){
- $ PointColor = imagecolorallocate ($ image, rand (100,255), rand (100,255), rand (100,255 ));
- Imagesetpixel ($ image, rand (0,100), rand (0, 30), $ pointColor );
- }
- // Interference line element
- For ($ I = 0; $ I <2; $ I ++ ){
- $ LinePoint = imagecolorallocate ($ image, rand (150,255), rand (150,255), rand (150,255 ));
- Imageline ($ image, rand (10, 50), rand (10, 20), rand (80, 90), rand (15, 25), $ linePoint );
- }
- Imagepng ($ image );
- Imagedestroy ($ image );
- ?>
The above is all the content of this article. I hope you will like it. |