Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // © w00p clan 2011
- define('CACHE_LIFETIME', 3600);
- define('FONT_SIZE', 14);
- header ("Content-type: image/png");
- // backgrounds URL
- // bug with PHP random number generation ? if I start with a real element, the last one is never chosen ?!
- // NVM
- $bgs = array("", "bg/power.jpg", "bg/desert.jpg", "bg/industrial.jpg", "bg/mines.jpg");/*, "bg/mines.jpg", "bg/industrial.jpg");*/
- $weaps = array("bg/sniper.png");
- function bg_init()
- {
- global $bgs;
- //return array_rand($bgs);
- return rand(1, count($bgs)-1);
- }
- // debbuging purposes
- error_reporting(E_ALL);
- // a player name must be specified
- if(empty($_GET['p']))
- {
- die();
- }
- $font = "BRLNSR.TTF";
- $month = "&month=".(string)(int)date('m');
- $prevmonth = "&month=".(string)(int)date('m', strtotime('-1 month'));
- // if "o" is enabled, we get overall stats
- // WIP
- if(!empty($_GET['o']))
- {
- $month = $prevmonth = "";
- }
- $encoded_playername = urlencode($playername = $_GET['p']);
- $player_id = md5($playername);
- // get a random background and his filename
- $bg = bg_init();
- $bgstring = $bgs[$bg];
- // if sig is cached...
- if(file_exists("sigs/$player_id$bg.png") && time() - filemtime("sigs/$player_id$bg.png") < CACHE_LIFETIME)
- {
- // read it and die
- readfile("sigs/$player_id$bg.png");
- die();
- }
- // get the xml stats of current and previous months
- $url = "http://ladder.tearyoudown.com/xml.cgi?filter=$encoded_playername$month&count=1";
- $prevurl = "http://ladder.tearyoudown.com/xml.cgi?filter=$encoded_playername$prevmonth&count=1";
- $xml = simplexml_load_file($url);
- $prevxml = simplexml_load_file($prevurl);
- $player = (array)$xml->Players[0]->Player;
- $prevplayer = (array)$prevxml->Players[0]->Player;
- $playername = $player['Name'];
- // player weapon
- // WIP
- $weap = 0;
- $weapstring = $weaps[$weap];
- // gd stuff
- // create a new image from the background
- $image = imagecreatefromjpeg($bgstring);
- if(!$image)
- {
- die();
- }
- // merge a filter with the background (make text readable)
- $im = imagecreate(imagesx($image), imagesy($image));
- $bgimage = imagecolorallocate($im, 0,0,0);
- imagecopymerge($image, $im, 0,0,0,0, imagesx($image), 30, 50);
- imagecopymerge($image, $im, 0, 85,0,0, imagesx($image), 500, 50);
- //$weapon = imagecreatefrompng($weapstring);
- //imagecopymerge($image, $weapon, 360,7,0,0, imagesx($weapon), imagesy($weapon), 85);
- $k = (array)$player['Killing'];
- $kills = $k['Kills'];
- $ratio = $k['Ratio'];
- $deaths = $k['Deaths'];
- $points = $player['Score'];
- $rank = $player['Rank'];
- $rank_2 = $prevplayer['Rank'];
- $flags = (array)$player['Flags'];
- $scored = $flags['Scored'];
- $ev = (string)$rank - $rank_2;
- if($ev >= 0)
- {
- $ev = "+ $ev";
- }
- if(!$month)
- {
- $date = "Overall";
- }
- else
- {
- $date = date('M Y');
- }
- // print text
- $white = imagecolorallocate($image, 255, 255, 255);
- $red = imagecolorallocate($image, 220, 40, 40);
- imagettftext($image, FONT_SIZE+2, 0, 15, 20, $white, $font, $playername);
- imagettftext($image, FONT_SIZE, 0, 300, 20, $red, $font, "TyD! Ladder - $date");
- imagettftext($image, FONT_SIZE, 0, 15, 110, $white, $font, "Score : $points");
- imagettftext($image, FONT_SIZE, 0, 160, 110, $white, $font, $month ? "Rank : $rank ($ev)" : "Rank : $rank");
- imagettftext($image, FONT_SIZE, 0, 320, 110, $white, $font, "Flags : $scored");
- imagettftext($image, FONT_SIZE, 0, 15, 137, $white, $font, "Kills : $kills");
- imagettftext($image, FONT_SIZE, 0, 160, 137, $white, $font, "Deaths : $deaths");
- imagettftext($image, FONT_SIZE, 0, 320, 137, $white, $font, "Ratio : $ratio");
- imagepng($image, "sigs/$player_id$bg.png");
- imagepng($image);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement