Page 1 of 1
Image saying how long I've been browsing this week
Posted: Sat Jun 17, 2006 7:25 pm
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!"
Posted: Sun Jun 18, 2006 12:18 am
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.");
}
Posted: Sun Jun 18, 2006 4:19 am
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?
Posted: Sun Jun 18, 2006 7:19 am
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
Posted: Sun Jun 18, 2006 9:17 am
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?
Posted: Sun Jun 18, 2006 9:53 am
by printf
Right above....
Code: Select all
imagestring($im, 7, $extralength, 0, $text, $textcolor);
Put...
Code: Select all
imagecolortransparent ( $im, $bg );
pif
Posted: Sun Jun 18, 2006 10:37 am
by m0u53m4t
Thanks. That works great. How do I change the font?