Show a simple graphics counter (this blog uses the counter), the code is as follows.
?
Header ("Content-type:image/png");
function CreateFile ($filename, $content)
{
if (Is_file ($filename))
{
@unlink ($filename);
}
$handle = fopen ($filename, "w"); Open file pointer, create file
/*
To check whether a file is created and writable
*/
if (!is_writable ($filename))
{
Die ("File:". $filename. " Not writable, please check its properties and try again. ");
}
if (!fwrite ($handle, $content))
{//write information to file
Die ("Generate file". $filename. " Failed. ");
}
echo "<br> write to File". $filename;
Fclose ($handle); Close the finger?
}
Srand (Double) microtime () *1000000);
$counterfile = ' blogcounter.txt ';
$counter = @file_get_contents ($counterfile);
$content = $counter +1;
@CreateFile ($counterfile, $content);
$len = strlen ($counter);
$im = Imagecreate (($len + 1) *10+5,15);
$black = Imagecolorallocate ($im, 0,255,0);
$white = Imagecolorallocate ($im, 255,255,255);
$green = Imagecolorallocate ($im, 223,11,216);
Imagefill ($im, 45,18, $white);
Imagefilledrectangle ($im, 0,0, ($len + 1) *10+5,20, $white);
To draw a counter into a picture
@ImageTTFText ($im, 8,0, 5,12, $green, "Counter.ttf", $counter);
Imagestring ($im, 4, 4, 1, $HTTP _get_vars[' Authnum '), $green);
For ($i =0 $i <200; $i + +)//Add interference pixels
{
Imagesetpixel ($im, Rand ()%50, Rand ()%50, $black);
}
Imagepng ($im);
Imagedestroy ($im);
?>
Attachment: Click to download