- $ Img = imagecreatetruecolor (100, 40 );
- $ Red = imagecolorallocate ($ img, 255, 0, 0 );
- $ Green = imagecolorallocate ($ img, 0,255, 0 );
- $ Blue = imagecolorallocate ($ img, 0, 0,255 );
- $ White = imagecolorallocate ($ img, 255,255,255 );
- $ Black = imagecolorallocate ($ img, 0, 0, 0 );
- // Generate an image
- Imagefill ($ img, 0, 0, $ black );
- // Set the verification code
- $ Code = "";
- For ($ I = 0; $ I <5; $ I ++ ){
- $ Code. = rand (0, 9 );
- }
- // Write the verification code to the image
- Imagestring ($ img, 5, 20, 15, $ code, $ white );
- // Add some interference
- For ($ I = 0; $ I <10; $ I ++ ){
- Imagesetpixel ($ img, rand (0,100), rand (0, 40), $ red );
- Imagesetpixel ($ img, rand (0,100), rand (0, 40), $ green );
- Imagesetpixel ($ img, rand (0,100), rand (0, 40), $ blue );
- }
- // Add some interference
- For ($ I = 0; $ I <1; $ I ++ ){
- Imageline ($ img, rand (0, 50), rand (50,100), rand (20, 40), $ red );
- Imageline ($ img, rand (0, 50), rand (50,100), rand (20, 40), $ green );
- Imageline ($ img, rand (0, 50), rand (50,100), rand (20, 40), $ blue );
- }
- Header ("Content-type: image/png ");
- Imagepng ($ img );
- Imagedestroy ($ img );
- ?>
|