|
<?php
Session_Start ();
Header ("Content-type:image/png");
Create a true Color white paper
$im = @imagecreatetruecolor (die) or ("Create image Failed");
Get background color
$background _color = imagecolorallocate ($im, 255, 255, 255);
Fill background color (this thing is similar to oil drums)
Imagefill ($im, 0,0, $background _color);
Get border color
$border _color = imagecolorallocate ($im, 200,200,200);
Draw a rectangle, border color 200,200,200
Imagerectangle ($im, 0,0,49,19, $border _color);
Show off the background by line, full screen with 1 or 0
For ($i =2 $i <18; $i + +) {
Get random tint
$line _color = Imagecolorallocate ($im, Rand (200,255), Rand (200,255), Rand (200,255));
Draw Line
Imageline ($im, 2, $i, $i, $line _color);
}
Set Font size
$font _size=12;
Set up the printed text
$Str [0] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$STR [1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$STR [2] = "01234567891234567890123456″;
Get 1th Random text
$imstr [0]["s"] = $Str [rand (0,2)][rand (0,25)];
$IMSTR [0]["x"] = rand (2,5);
$imstr [0]["y"] = rand (1,4);
Get 2nd random Text
$imstr [1]["s"] = $Str [rand (0,2)][rand (0,25)];
$IMSTR [1]["x"] = $imstr [0]["x"]+ $font _size-1+rand (0,1);
$imstr [1]["y"] = rand (1,3);
Get 3rd random text
$imstr [2]["s"] = $Str [rand (0,2)][rand (0,25)];
$IMSTR [2]["x"] = $imstr [1]["x"]+ $font _size-1+rand (0,1);
$imstr [2]["y"] = rand (1,4);
Get 4th Random Text
$imstr [3]["s"] = $Str [rand (0,2)][rand (0,25)];
$IMSTR [3]["x"] = $imstr [2]["x"]+ $font _size-1+rand (0,1);
$imstr [3]["y"] = rand (1,3);
Assign the displayed array to the session
$_session[' CODE ' = $imstr [0]["S"]. $imstr [1]["S"]. $imstr [2]["S"]. $imstr [3]["S"];
//write Random Strings
for ($i =0 $i <4; $i + +) {
$text _color = imagecolorallocate ($im, Rand (50,180), Rand (50,180), Rand ( 50,180));
Imagechar ($im, $font _size, $imstr [$i] ["X"], $imstr [$i] ["Y"], $imstr [$i] ["s"], $text _color);
}
///Show Picture
Imagepng ($im);
//Destroy picture
Imagedestroy ($im);
|