- Getvalidate (100,30);
- function Getvalidate ($w, $h) {
- $img = Imagecreate ($w, $h);
- $gray = Imagecolorallocate ($img, 255,255,255);
- $black = Imagecolorallocate ($img, Rand (0,200), Rand (0,200), Rand (0,200));
- $red = Imagecolorallocate ($img, 255, 0, 0);
- $white = Imagecolorallocate ($img, 255, 255, 255);
- $green = imagecolorallocate ($img, 0, 255, 0);
- $blue = imagecolorallocate ($img, 0, 0, 255);
- Imagefilledrectangle ($img, 0, 0, +, $black);
- for ($i = 0; $i < $i + +) {
- Imagesetpixel ($img, rand (0, $w), rand (0, $h), $gray);
- }
- $num 1 = rand (1,99);
- $num 2 = rand (1,99);
- Imagestring ($img, 5, 5, rand (1,10), $num 1, $red);
- Imagestring ($img, 5,30,rand (1,10), Getrand (), $white);
- Imagestring ($img, 5,45,rand (1,10), $num 2, $green);
- Imagestring ($img, 5,65,rand (1,10), "=", $blue);
- Imagestring ($img, 5,80,rand (1,10), "?", $red);
- Header ("Content-type:image/png");
- Imagepng ($IMG);
- Imagedestroy ($IMG);
- }
- function Getrand () {
- $code = rand (0,1);
- Switch ($code) {
- Case 0:
- return "+";
- Break
- Case 1:
- Return "-";
- Break
- Default
- # code ...
- Break
- }
- }
- ?>
Copy Code
|