Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- function formatTime($time){
- $time_seconds = $time / 1000;
- $time_minutes = $time_seconds / 60;
- $time_hours = $time_minutes / 60;
- $time_days = floor($time_hours / 24);
- $seconds = $time_seconds % 60;
- $minutes = $time_minutes % 60;
- $hours = $time_hours % 24;
- $days = floor($time_days % 365);
- $years = floor($time_days / 365);
- return $years . "y " . $days . "d " .$hours . "h " . $minutes . "m ";
- }
- $username=""; //Your MySQL Username.
- $password=""; // Your MySQL Pass.
- $database=""; // Your MySQL database.
- $host=""; // Your MySQL host. This is "localhost" or the IP specified by your hosting company.
- $player_name=$_GET['player_name']; // This gets the player his name from the previous page.
- mysql_connect($host,$username,$password); // Connection to the database.
- @mysql_select_db($database) or die( "Unable to select database. Be sure the databasename exists and online is."); //Selection of the database. If it can't read the database, it'll give an error.
- /* To protect MySQL injection. */
- $player_name = stripslashes($player_name);
- $player_name = mysql_real_escape_string($player_name);
- /* */
- if($player_name == "ALL"){ // If you want to sum all of your users data, like I have in my signature, you need this.
- $query="SELECT SUM(timeran) as timesum FROM Data";
- $result=mysql_query($query);
- $Timeran1= mysql_fetch_assoc($result);
- $Timeran = $Timeran1[timesum];
- $query="SELECT SUM(expgained) as expsum FROM Data";
- $result=mysql_query($query);
- $ExpGained1= mysql_fetch_assoc($result);
- $ExpGained = $ExpGained1[expsum];
- // Now for the creation of the image.
- header('Content-Type: image/png;');
- // Your image must be in the same directory as your PHP Scripts for it to work, otherwise you will need to include a path
- $im = @imagecreatefrompng('YOUR_IMAGE.png') or die("Cannot find image, check naming and file location");
- $text_color = imagecolorallocate($im, 255,255,100); // RED, GREEN, BLUE , you can goto http://colorpicker.com to pick a nice colour if you wish.
- $text_username = "ALL"; // This gets the information about player name to be showed in the picture.
- $text_timeran = formatTime($Timeran); // Same as above ^^
- $text_expgained = number_format($ExpGained);
- $font = 'Calibri.ttf'; //Upload your custum font to the directory where this file is placed if you wish to customise it.
- // 18 is the font size, 0 is the angel of the text, 165 is the x coordinate on your image, and 132 is the Y coordinate on your image.
- imagettftext($im, 18, 0, 165, 132, $text_color, $font, 'ALL');
- imagettftext($im, 12, 0, 300, 93, $text_color, $font, $text_timeran);
- imagettftext($im, 14, 0, 130, 93, $text_color, $font, $text_expgained);
- imagepng($im);
- imagedestroy($im);
- return;
- }
- // Below is the code for regular players, it will not SUM
- $query="SELECT * FROM Data WHERE Username='$player_name'"; // Gets all the information about the player.
- $result=mysql_query($query);
- $i=mysql_num_rows($result); // Here we are counting how many rows this result gives us.
- if ($i == 1) // If the user has been correct, then it'll give us 1 row. If its 1 row, then it'll proceed with the code.
- {
- $Username=mysql_result($result,0,"Username");
- $Timeran=mysql_result($result,0,"timeran");
- $ExpGained=mysql_result($result,0,"expgained");
- // Creating of the .png image.
- header('Content-Type: image/png;');
- header('Content-Type: image/png;');
- // Your image must be in the same directory as your PHP Scripts for it to work, otherwise you will need to include a path
- $im = @imagecreatefrompng('YOUR_IMAGE.png') or die("Cannot find image, check naming and file location");
- $text_color = imagecolorallocate($im, 255,255,100); // RED, GREEN, BLUE , you can goto http://colorpicker.com to pick a nice colour if you wish.
- $text_username = "$Username"; // This gets the information about player name to be showed in the picture. // This gets the information about player name to be showed in the picture.
- $text_timeran = formatTime($Timeran); // Same as above ^^
- $text_expgained = number_format($ExpGained);
- $font = 'Calibri.ttf'; //Upload your custum font to the directory where this file is placed. Then change the name here.
- // 18 is the font size, 0 is the angel of the text, 165 is the x coordinate on your image, and 132 is the Y coordinate on your image.
- imagettftext($im, 12, 0, 138, 130, $text_color, $font, $text_username);
- imagettftext($im, 12, 0, 300, 93, $text_color, $font, $text_timeran);
- imagettftext($im, 14, 0, 138, 93, $text_color, $font, $text_expgained);
- imagepng($im);
- imagedestroy($im);
- } else echo('Username is not in our database. Please try again.'); // If the username doesn't exist (so the row is 0) then it'll give en error.
- mysql_close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement