Advertisement
lucasgautheron

Untitled

Sep 17th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.60 KB | None | 0 0
  1. <?php
  2. // © w00p clan 2011
  3. define('CACHE_LIFETIME', 3600);
  4. define('FONT_SIZE', 14);
  5.  
  6. header ("Content-type: image/png");
  7.  
  8. // backgrounds URL
  9. // bug with PHP random number generation ? if I start with a real element, the last one is never chosen ?!
  10. // NVM
  11. $bgs = array("", "bg/power.jpg", "bg/desert.jpg", "bg/industrial.jpg", "bg/mines.jpg");/*, "bg/mines.jpg", "bg/industrial.jpg");*/
  12.  
  13. $weaps = array("bg/sniper.png");
  14.  
  15. function bg_init()
  16. {
  17.     global $bgs;
  18.     //return array_rand($bgs);
  19.     return rand(1, count($bgs)-1);
  20. }
  21.  
  22. // debbuging purposes
  23. error_reporting(E_ALL);
  24.  
  25. // a player name must be specified
  26. if(empty($_GET['p']))
  27. {
  28.     die();
  29. }
  30. $font = "BRLNSR.TTF";
  31.  
  32. $month = "&month=".(string)(int)date('m');
  33. $prevmonth = "&month=".(string)(int)date('m', strtotime('-1 month'));
  34.  
  35. // if "o" is enabled, we get overall stats
  36. // WIP
  37. if(!empty($_GET['o']))
  38. {
  39.     $month = $prevmonth = "";
  40. }
  41.  
  42.  
  43. $encoded_playername = urlencode($playername = $_GET['p']);
  44. $player_id = md5($playername);
  45.  
  46. // get a random background and his filename
  47. $bg = bg_init();
  48. $bgstring = $bgs[$bg];
  49.  
  50. // if sig is cached...
  51. if(file_exists("sigs/$player_id$bg.png") && time() - filemtime("sigs/$player_id$bg.png") < CACHE_LIFETIME)
  52. {
  53.     // read it and die
  54.     readfile("sigs/$player_id$bg.png");
  55.     die();
  56. }
  57.  
  58. // get the xml stats of current and previous months
  59. $url = "http://ladder.tearyoudown.com/xml.cgi?filter=$encoded_playername$month&count=1";
  60. $prevurl = "http://ladder.tearyoudown.com/xml.cgi?filter=$encoded_playername$prevmonth&count=1";
  61. $xml = simplexml_load_file($url);
  62. $prevxml = simplexml_load_file($prevurl);
  63.  
  64. $player = (array)$xml->Players[0]->Player;
  65. $prevplayer = (array)$prevxml->Players[0]->Player;
  66.  
  67. $playername = $player['Name'];
  68.  
  69. // player weapon
  70. // WIP
  71. $weap = 0;
  72. $weapstring = $weaps[$weap];
  73.  
  74. // gd stuff
  75. // create a new image from the background
  76. $image = imagecreatefromjpeg($bgstring);
  77. if(!$image)
  78. {
  79.     die();
  80. }
  81.  
  82.  
  83. // merge a filter with the background (make text readable)
  84. $im = imagecreate(imagesx($image), imagesy($image));
  85. $bgimage = imagecolorallocate($im, 0,0,0);
  86. imagecopymerge($image, $im, 0,0,0,0, imagesx($image), 30, 50);
  87.  
  88. imagecopymerge($image, $im, 0, 85,0,0, imagesx($image), 500, 50);
  89.  
  90. //$weapon = imagecreatefrompng($weapstring);
  91. //imagecopymerge($image, $weapon, 360,7,0,0, imagesx($weapon), imagesy($weapon), 85);
  92.  
  93. $k = (array)$player['Killing'];
  94. $kills = $k['Kills'];
  95. $ratio = $k['Ratio'];
  96. $deaths = $k['Deaths'];
  97. $points = $player['Score'];
  98. $rank = $player['Rank'];
  99. $rank_2 = $prevplayer['Rank'];
  100. $flags = (array)$player['Flags'];
  101. $scored = $flags['Scored'];
  102. $ev = (string)$rank - $rank_2;
  103. if($ev >= 0)
  104. {
  105.     $ev = "+ $ev";
  106. }
  107.  
  108. if(!$month)
  109. {
  110.     $date = "Overall";
  111. }
  112. else
  113. {
  114.     $date = date('M Y');
  115. }
  116.  
  117. // print text
  118. $white = imagecolorallocate($image, 255, 255, 255);
  119. $red = imagecolorallocate($image, 220, 40, 40);
  120. imagettftext($image, FONT_SIZE+2, 0, 15, 20, $white, $font, $playername);
  121. imagettftext($image, FONT_SIZE, 0, 300, 20, $red, $font, "TyD! Ladder - $date");
  122. imagettftext($image, FONT_SIZE, 0, 15, 110, $white, $font, "Score : $points");
  123. imagettftext($image, FONT_SIZE, 0, 160, 110, $white, $font, $month ? "Rank : $rank ($ev)" : "Rank : $rank");
  124. imagettftext($image, FONT_SIZE, 0, 320, 110, $white, $font, "Flags : $scored");
  125. imagettftext($image, FONT_SIZE, 0, 15, 137, $white, $font, "Kills : $kills");
  126. imagettftext($image, FONT_SIZE, 0, 160, 137, $white, $font, "Deaths : $deaths");
  127. imagettftext($image, FONT_SIZE, 0, 320, 137, $white, $font, "Ratio : $ratio");
  128.  
  129. imagepng($image, "sigs/$player_id$bg.png");
  130. imagepng($image);
  131. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement