Jump to content

php counter / Custom numbers


iceman023

Recommended Posts

  • 2 weeks later...

Well u need the images of the numbers

I came up with this code

<?php

// Get and update our counter
$counter=(file_exists('counter.txt') && (($counter=file_get_contents('counter.txt'))>0))?$counter+1:1;
file_put_contents('counter.txt',$counter);

// Max Numbers to appear on counter
define('MAX_NUMBERS',3);

// Pad Counter with 0's
$counter=substr(str_repeat('0',MAX_NUMBERS).$counter,-MAX_NUMBERS);

// Get Number Images Attributes (Width & Height)
$iinfo=getimagesize('pics/0.gif');

$cw=$iinfo[0];
$ch=$iinfo[1];

// Calculate Max Width
$iw=$cw*MAX_NUMBERS;

// Create image canvas for counter
$ci=imagecreate($iw,$ch);


// Loop to get image of each digit
for($i=0;$i<MAX_NUMBERS;$i++)
{
   // Grab Next Number in $counter
   $num=substr($counter,$i,1);
   // If Number use number image otherwise blank
   $num=ctype_digit($num)?$num:'blank';
  // Do We have the image already?
   if(!isset($images[$num]))
       // No, Load the image
     $images[$num] =  imagecreatefromgif("pics/{$num}.gif");
   // Place image in correct place on new counter image
   imagecopy($ci,$images[$num],$i*$cw,0,0,0,$cw,$ch);
}

// tell browser we displaying a gif
header('Content-type: image/gif');

// Show our image
imagegif($ci);
?>

 

See nothing to it, just make shure gd2 extension is loaded.

 

Well up to u to take this and make it better :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.