Hey,
Is there a way using PHP to get certain statistics from a specific website and arrange them on an image? (Yes, it is typically a dynamic image generator.)
6 1330
for the picture part you can use rrdtools to create a graph and jpg it.
i assume you have access to that website you want to gather information about.
you can customize your apache log and from that log create the graph.
by using a script that runs as cronjob and refresh your rrdtools graph.
In fact, what I'm trying to do is get some stats from a certain game website, such as kills and those stuff depending on the user that has been input. It is for promotional puposes for my website.
You will need to make your own for that. You will have to record a history and then query the target user to collect the history for that user. This could become a very big database and could take some time to set up, but when I am finished my game I will have something like that, so it can be done! Not sure about graphing yet though.
This would probably be an example of what I want: - <?
-
$accountName = $_GET['name'];
-
$statsURL = "http://example.com/profile/$accountName?xml=true";
-
-
$stats = @simplexml_load_file($statsURL) or die("Failed to retreieve stats XML for user $accountName");
-
-
header("Content-type: image/png");
-
$img = imagecreatefrompng("bg.png");
-
-
// Colors
-
$c_white = imagecolorallocate($img, 255, 255, 255);
-
$c_black = imagecolorallocate($img, 0, 0, 0);
-
-
// Misc
-
$statsLeft = 160;
-
$statsTop = 5;
-
-
// Name & Rank
-
$nameString = $stats->user_info['military_rank'] . " " . $stats->user_info['username'];
-
$size = 18;
-
$bbox = imagettfbbox($size, 0, "./helr67w.ttf", $nameString);
-
while ($bbox[4] > (imagesx($img) - $statsLeft - 4)) {
-
$size--;
-
$bbox = imagettfbbox($size, 0, "./helr67w.ttf", $nameString);
-
}
-
-
// Clan
-
if ($stats->user_info->clan['clan_name'] != "") $clanString = $stats->user_info->clan['clan_name'] ."\n";
-
-
// General Stats
-
$timeString = "Hours Played: " . round($stats->misc['total_time_played'] / 3600, 2);
-
$xpString = "XP: " . round($stats->total['xp']);
-
$rankString = "Rank: " . $stats->user_info['rank'];
-
-
// K/D Ratio
-
$kills = $stats->misc['total_kills'];
-
$deaths = $stats->misc['total_deaths'];
-
$ratio = round((float) $stats->total['kill_death_ratio'], 2);
-
$ratioString = "K/D: $kills/$deaths ($ratio)";
-
-
-
// Favorite Class
-
$timeArray = array();
-
foreach ($stats->classes->children() as $class) $timeArray[$class->getName()] = (string) $class['time_used'];
-
arsort($timeArray);
-
$classImg = imagecreatefrompng("classes/".key($timeArray).".png");
-
imagecopy($img, $classImg, 5, 5, 0, 0, imagesx($classImg), imagesy($classImg));
-
-
// Favorite Vehicle
-
$timeArray = array();
-
foreach ($stats->vehicles->children() as $vehicle) $timeArray[$vehicle->getName()] = (string) $vehicle['total_time_spent'];
-
arsort($timeArray);
-
$vehicleImg = imagecreatefrompng("vehicles/".key($timeArray).".png");
-
imagecopy($img, $vehicleImg, 82, 6, 0, 0, imagesx($vehicleImg), imagesy($vehicleImg));
-
-
// Favorite Weapon
-
$timeArray = array();
-
foreach ($stats->weapons->children() as $weapon) $timeArray[$weapon->getName()] = (string) $weapon['time_used'];
-
arsort($timeArray);
-
while ( strstr(key($timeArray),"combined") ) next($timeArray);
-
$weaponImg = imagecreatefrompng("weapons/".key($timeArray).".png");
-
imagecopy($img, $weaponImg, 82, 53, 0, 0, imagesx($weaponImg), imagesy($weaponImg));
-
-
-
// Draw the text
-
imagettftext($img, $size, 0, $statsLeft + 2, $statsTop + 22, $c_black, "./helr67w.ttf", $nameString);
-
imagettftext($img, $size, 0, $statsLeft, $statsTop + 20, $c_white, "./helr67w.ttf", $nameString);
-
-
$statsText = <<<EOT
-
$rankString
-
$timeString
-
$xpString
-
$ratioString
-
EOT;
-
-
imagettftext($img, 10, 0, $statsLeft + 1, $statsTop + 41, $c_black, "./helr65w.ttf", $statsText);
-
imagettftext($img, 10, 0, $statsLeft, $statsTop + 40, $c_white, "./helr65w.ttf", $statsText);
-
-
imagepng($img);
-
umm you want to get data from a website... that is not your?
you can use curl to get the webpage and the game info
and play with that info
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dan glenn |
last post by:
My client wants to see stats which tell him the number of hits he's getting
from different countries. I'm coding page hit count stats myself in PHP on
his site, which is simple enough, but haven't...
|
by: Bob II |
last post by:
Hey, I've never used PHP before. I was wondering if it is possible to use
PHP to generate web stats. My web host's stats aren't very good. So I
want to generate some custom stats for myself.
...
|
by: middletree |
last post by:
How do I request the actual page name that I'm on? This is going to go into
an include file, and depending on which page I'm on, I'd like to do
different things. I'm looking for "pagename.asp"
|
by: dba |
last post by:
Hi
I am a new MySQL dba tuning a busy Apache/MySQL installation. Here are
some of the
statistics for the last 24 hours:
Com_admin_commands 978,760
What "Admin_Commands" does this...
|
by: Derrick King |
last post by:
COuld someone tell me if its possible to get hold of stats about all
Databases on a SQL Server.
The sort of things I would like are
Name of DB
Location of DB
Size of DB
Location of Logfile...
|
by: (PeteCresswell) |
last post by:
Help Desk at a client site steered me to TaskMan's LAN stats window, but advised
that Windows makes it's own decisions about how much bandwidth each app gets.
Looks to me like there's plenty...
|
by: marklawford |
last post by:
Not having earned my DBA badge from the scouts just yet I'm a little
lost with an error I'm getting.
We've just upgraded our development database from 7.2 to 8.2 as the
first step in upgrading...
|
by: MKoool |
last post by:
Is there any decent library for basic stats? I am just looking for the
basics, like quartiles, median, standard deviation, mean, min, max,
regression, etc.
I was going to use SciPy, but I use...
|
by: tkpmep |
last post by:
I installed SciPy and NumPy (0.9.5, because 0.9.6 does not work with
the current version of SciPy), and had some teething troubles. I looked
around for help and observed that the tutorial is dated...
|
by: jeff.maildump |
last post by:
Hi,
I've got multiple xmlhttprequests which are in a loop. So this is the
loop I have so far, with the closure given to me in a previous post:
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |