#native_company# #native_desc#
#native_cta#

GDLib Hit Counter

By Dave
on October 22, 2001

Version: 1

Type: Full Script

Category: Voting

License: GNU General Public License

Description: A graphic hit counter that uses the GD Lib to Merge a background with the number images

<?php
//counter.php
//
//Simply create a text file with 0000 (four zero's) in it.
//then place your text file, background image and your 10 number
//images (1.jpg, 2.jpg, 3.jpg........9.jpg, 0..jpg) in the same
//directory as this file.
//
//To place the counter on your page simply insert a <IMG> tag into
//your code calling this file e.g. <img src="counter.php">

//Declare filename
$file = "counter.txt";

//read data from file declared
$data = file($file);

//increment counter value from file by one
$data[0]++;

//write new counter value to file
$fileout = fopen($file, "w+");
fwrite ($fileout, $data[0]);
fclose($fileout);

//Assign each digit from declared file to different variable name
$num1 = substr($data[0],0,1);
$num2 = substr($data[0],1,1);
$num3 = substr($data[0],2,1);
$num4 = substr($data[0],3,1);

//Declare background image
Header("Content-type: image/jpeg");
$image = ImageCreateFromJPEG("background.jpg");

//Add first image to backround image
$icon = ImageCreateFromJPEG("$num1.jpg");
$width = ImageSX($icon);
$height = ImageSY($icon);
ImageCopyResized($image,$icon,25,52,
	0,0,$width,$height,$width,$height);

//Add second image to backround image
$icon = ImageCreateFromJPEG("$num2.jpg");
$width = ImageSX($icon);
$height = ImageSY($icon);
ImageCopyResized($image,$icon,62,53,
	0,0,$width,$height,$width,$height);

//Add third image to backround image
$icon = ImageCreateFromJPEG("$num3.jpg");
$width = ImageSX($icon);
$height = ImageSY($icon);
ImageCopyResized($image,$icon,93,52,
	0,0,$width,$height,$width,$height);

//Add forth image to backround image
$icon = ImageCreateFromJPEG("$num4.jpg");
$width = ImageSX($icon);
$height = ImageSY($icon);
ImageCopyResized($image,$icon,128,51,
	0,0,$width,$height,$width,$height);
	
//return new image
ImageJPEG($image);

//remove new image from memory
ImageDestroy($image);
?>