Reputation: 1232
I'm using simple php script to count visits. It's saved inside file. So there is a number inside a .txt file and I would like to put on my page in a form of some nice counter. So I need numbers to be represented as images in some way. So it can look nice. If I eventually had div where I can show this numbers, and 10 images of numbers from 0 to 9. 25x50px lets say and I would like to put them into tags is that possible? I know my question is a bit dodgy and maybe not clear. But if someone understand what I'm asking for than if you could answer that would be great. Thx
Upvotes: 0
Views: 1126
Reputation: 4042
have 10 images for the numbers 0-9 (0.png, 1.png, ...) and just convert every character in a string $counter="12345"
into a corresponding image <img src="1.png" />
this is explained and implemented in javascript on this website.
you may also want to str_pad
your $counter with 0
.
Upvotes: 0
Reputation: 645
Split the number into digits:
$a = str_split(1337, 1);
Use the array to create the counter:
foreach ($a as $n) {
print '<img src="'.$n.'.png">';
}
Upvotes: 2
Reputation: 5917
If your problem is only showing the number as images, it's easy. Do something like:
$num = 1234;
for ($i = 0; $i < strlen($num); $i++)
echo "<img src=\"images/numbers/" . $num.{$i} . ".png\">";
Upvotes: 0
Reputation: 75588
To get the number from the file:
$number = file_get_contents('visitors.txt');
To create an image, use the GD or Imagick library:
header("Content-type: image/png");
$im = imagecreatefrompng("images/button1.png");
// Add text to $im
imagepng($im);
To include your image in a page:
<img src="myImageScript.php?number=1234" />
Upvotes: 1
Reputation: 714
Yes it is possible. First you need to get the number in char array and the proceed. Based on number display the images nest to each other.
Upvotes: 0