Advertisement
opsftw

Runescape Stats Picture Generator

Apr 8th, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.22 KB | None | 0 0
  1. <?php
  2. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3.  * @Script Runescape Stats Image Generator                             *
  4.  * @Author Tuxedo                                                      *
  5.  * @Description You call the file like "file.php?user=(Username)" and  *
  6.  * it looks up and formats the users levels of OSRS into a picture as  *
  7.  * like how it shows it in the game.                                   *
  8.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  9.  
  10.  Get the font here http://www.fonts101.com/fonts/view/Standard/57559/Rupee_Foradian
  11.  and store it in the same directory as the class and get the base image here
  12.  http://i.imgur.com/Xm5vS8y.png and store it in a folder named img/ and name it
  13.  base.png and you're all good to go :)
  14. */
  15. if(empty($_GET['user'])) {
  16.     die('Usage: ?user={IGN}');
  17. }
  18. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  19. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  20. header("Cache-Control: no-store, no-cache, must-revalidate");
  21. header("Cache-Control: post-check=0, pre-check=0", false);
  22. header("Pragma: no-cache");
  23. header("Content-type: image/png");
  24.  
  25. class stats
  26. {
  27.     /* * * * * * * * * * * * * * * *\
  28.      * @Class stats                *
  29.      * @Author Tuxedo              *
  30.      * @Description fetch a users  *
  31.      * stats and format them into  *
  32.      * a pretty little picture.    *
  33.     \* * * * * * * * * * * * * * * */
  34.     public function statPic( $user ) {
  35.         # fetch the base image and create a resource from it
  36.         $img = imagecreatefrompng('img/base.png');
  37.        
  38.         #create the color for the text
  39.         $yellow = imagecolorallocate($img, 255, 255, 51);
  40.        
  41.         # fetch users levels
  42.         $level = $this->highScore($user);
  43.        
  44.         # Row 1
  45.         //attack
  46.         imagettftext($img, 9, 0, 72, 22, $yellow, './font.ttf', $level['attack']['level']);
  47.         imagettftext($img, 9, 0, 88, 35, $yellow, './font.ttf', $level['attack']['level']);
  48.         //hitpoints
  49.         imagettftext($img, 9, 0, 155, 22, $yellow, './font.ttf', $level['hitpoints']['level']);
  50.         imagettftext($img, 9, 0, 172, 35, $yellow, './font.ttf', $level['hitpoints']['level']);
  51.         //mining
  52.         imagettftext($img, 9, 0, 235, 22, $yellow, './font.ttf', $level['mining']['level']);
  53.         imagettftext($img, 9, 0, 252, 35, $yellow, './font.ttf', $level['mining']['level']);
  54.         # Row 2
  55.         //strength
  56.         imagettftext($img, 9, 0, 72, 60, $yellow, './font.ttf', $level['strength']['level']);
  57.         imagettftext($img, 9, 0, 88, 73, $yellow, './font.ttf', $level['strength']['level']);
  58.         //agility
  59.         imagettftext($img, 9, 0, 155, 60, $yellow, './font.ttf', $level['agility']['level']);
  60.         imagettftext($img, 9, 0, 172, 73, $yellow, './font.ttf', $level['agility']['level']);
  61.         //smithing
  62.         imagettftext($img, 9, 0, 235, 60, $yellow, './font.ttf', $level['smithing']['level']);
  63.         imagettftext($img, 9, 0, 252, 73, $yellow, './font.ttf', $level['smithing']['level']);
  64.         # Row 3
  65.         //defence
  66.         imagettftext($img, 9, 0, 72, 98, $yellow, './font.ttf', $level['defence']['level']);
  67.         imagettftext($img, 9, 0, 88, 111, $yellow, './font.ttf', $level['defence']['level']);
  68.         //herblore
  69.         imagettftext($img, 9, 0, 155, 98, $yellow, './font.ttf', $level['herblore']['level']);
  70.         imagettftext($img, 9, 0, 172, 111, $yellow, './font.ttf', $level['herblore']['level']);
  71.         //fishing
  72.         imagettftext($img, 9, 0, 235, 98, $yellow, './font.ttf', $level['fishing']['level']);
  73.         imagettftext($img, 9, 0, 252, 111, $yellow, './font.ttf', $level['fishing']['level']);
  74.         # Row 4
  75.         //ranged
  76.         imagettftext($img, 9, 0, 73, 136, $yellow, './font.ttf', $level['ranged']['level']);
  77.         imagettftext($img, 9, 0, 88, 149, $yellow, './font.ttf', $level['ranged']['level']);
  78.         //thieving
  79.         imagettftext($img, 9, 0, 155, 136, $yellow, './font.ttf', $level['thieving']['level']);
  80.         imagettftext($img, 9, 0, 172, 149, $yellow, './font.ttf', $level['thieving']['level']);
  81.         //cooking
  82.         imagettftext($img, 9, 0, 235, 136, $yellow, './font.ttf', $level['cooking']['level']);
  83.         imagettftext($img, 9, 0, 252, 149, $yellow, './font.ttf', $level['cooking']['level']);
  84.         # Row 5
  85.         //prayer
  86.         imagettftext($img, 9, 0, 72, 174, $yellow, './font.ttf', $level['prayer']['level']);
  87.         imagettftext($img, 9, 0, 88, 187, $yellow, './font.ttf', $level['prayer']['level']);
  88.         //crafting
  89.         imagettftext($img, 9, 0, 155, 174, $yellow, './font.ttf', $level['crafting']['level']);
  90.         imagettftext($img, 9, 0, 172, 187, $yellow, './font.ttf', $level['crafting']['level']);
  91.         //firemaking
  92.         imagettftext($img, 9, 0, 235, 174, $yellow, './font.ttf', $level['firemaking']['level']);
  93.         imagettftext($img, 9, 0, 252, 187, $yellow, './font.ttf', $level['firemaking']['level']);
  94.         # Row 6
  95.         //magic
  96.         imagettftext($img, 9, 0, 72, 211, $yellow, './font.ttf', $level['magic']['level']);
  97.         imagettftext($img, 9, 0, 88, 224, $yellow, './font.ttf', $level['magic']['level']);
  98.         //fletching
  99.         imagettftext($img, 9, 0, 155, 211, $yellow, './font.ttf', $level['fletching']['level']);
  100.         imagettftext($img, 9, 0, 172, 224, $yellow, './font.ttf', $level['fletching']['level']);
  101.         //woodcutting
  102.         imagettftext($img, 9, 0, 235, 211, $yellow, './font.ttf', $level['woodcutting']['level']);
  103.         imagettftext($img, 9, 0, 252, 224, $yellow, './font.ttf', $level['woodcutting']['level']);
  104.         # Row 7
  105.         //runecraft
  106.         imagettftext($img, 9, 0, 72, 248, $yellow, './font.ttf', $level['runecraft']['level']);
  107.         imagettftext($img, 9, 0, 88, 261, $yellow, './font.ttf', $level['runecraft']['level']);
  108.         //slayer
  109.         imagettftext($img, 9, 0, 155, 248, $yellow, './font.ttf', $level['slayer']['level']);
  110.         imagettftext($img, 9, 0, 172, 261, $yellow, './font.ttf', $level['slayer']['level']);
  111.         //farming
  112.         imagettftext($img, 9, 0, 235, 248, $yellow, './font.ttf', $level['farming']['level']);
  113.         imagettftext($img, 9, 0, 252, 261, $yellow, './font.ttf', $level['farming']['level']);
  114.         # Row 8
  115.         //construction
  116.         imagettftext($img, 9, 0, 72, 285, $yellow, './font.ttf', $level['construction']['level']);
  117.         imagettftext($img, 9, 0, 88, 299, $yellow, './font.ttf', $level['construction']['level']);
  118.         //hunter
  119.         imagettftext($img, 9, 0, 155, 285, $yellow, './font.ttf', $level['hunter']['level']);
  120.         imagettftext($img, 9, 0, 172, 299, $yellow, './font.ttf', $level['hunter']['level']);
  121.         //total levels
  122.         imagettftext($img, 9, 0, 201, 299, $yellow, './font.ttf', $level['overall']['level']);
  123.        
  124.         # return the image
  125.         imagepng($img);
  126.     }
  127.  
  128.     public function highScore( $user ) {
  129.         $order = array(
  130.             "Overall", "Attack", "Defence",
  131.             "Strength", "Hitpoints", "Ranged",
  132.             "Prayer", "Magic", "Cooking", "Woodcutting",
  133.             "Fletching", "Fishing", "Firemaking",
  134.             "Crafting", "Smithing", "Mining",
  135.             "Herblore", "Agility", "Thieving",
  136.             "Slayer", "Farming", "Runecraft",
  137.             "Hunter", "Construction", "Summoning"
  138.         );
  139.         $get = file_get_contents("http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player={$user}");
  140.         $get = explode("\n", $get);
  141.         $i = 0;
  142.         foreach ($order as $value) {
  143.             $temp  = explode(",", $get[$i]);
  144.             $rank  = (empty($temp[0]))?'':$temp[0];
  145.             $level = (empty($temp[0]))?'':$temp[1];
  146.             $exp   = (empty($temp[2]))?'':$temp[2];
  147.             $stats[strtolower($value)] = array("rank" => $rank, "level" => $level, "exp" => $exp);
  148.             $i++;
  149.         }
  150.         return $stats;
  151.     }
  152. }
  153.  
  154. $stats = new stats;
  155. echo $stats->statPic($_GET['user']);
  156. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement