Image saying how long I've been browsing this week

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
m0u53m4t
Forum Contributor
Posts: 101
Joined: Wed Apr 19, 2006 7:47 am
Location: Wales

Image saying how long I've been browsing this week

Post by m0u53m4t »

I've seen these kind of things generated by XFIRE but I want a image that updates itself that can say how many hours I've been on the browsing this week. I've decided to write a vb program to tell how long I've been on, but need to know how to make php read a file (named time.php) that contains this: "2:12" and say "I've been online 2 days and 12 hours this week!"
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Just do:

Code: Select all

<?php 

include("time.php");
/*
// Make sure in your php page time.php that it contains something like 
$time = 2:12;
// or have it be like
$days = 2 ;
$hours = 12;
*/

// This is only needed if you don't have them seperated into two variables 
$splitdata = explode(':', $time);
$days = $splitdata[0];
$hours = $splitdata[1];

// Make sure that there is at least 1 hours 
if($hours>=1){
// If yes print:
    $message = 'I\'ve been online '. $days . 'days and '. $hours . 'hours this week!';
    print("$message");
} else {
    print("I've not been online over an hour this week.");
}
User avatar
m0u53m4t
Forum Contributor
Posts: 101
Joined: Wed Apr 19, 2006 7:47 am
Location: Wales

Post by m0u53m4t »

Thats good, but I need it to put that as text over an image for a sig image. How could I do that?
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

m0u53m4t wrote:Thats good, but I need it to put that as text over an image for a sig image. How could I do that?
By using the GD library and imagestring.

Greetings,
Marc
User avatar
m0u53m4t
Forum Contributor
Posts: 101
Joined: Wed Apr 19, 2006 7:47 am
Location: Wales

Post by m0u53m4t »

Ok. So this is my code now:

Code: Select all

<?php

$nums = file_get_contents("time.php");
$time = explode(':', $nums);
$text = "I've been online for $time[0] days and $time[1] hours this week!";
$extralength = 3;
$length = (strlen($text)) * 9 + $extralength;
$im = imagecreate($length, 19);

// white background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 000, 000, 000);

// write the string at the top left
imagestring($im, 7, $extralength, 0, $text, $textcolor);

// output the image
header("Content-type: image/png");
imagepng($im);
?>
How can I make the background transparent? Or put an image in the background?
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post by printf »

Right above....

Code: Select all

imagestring($im, 7, $extralength, 0, $text, $textcolor);

Put...

Code: Select all

imagecolortransparent ( $im, $bg );
pif
User avatar
m0u53m4t
Forum Contributor
Posts: 101
Joined: Wed Apr 19, 2006 7:47 am
Location: Wales

Post by m0u53m4t »

Thanks. That works great. How do I change the font?
Post Reply