Minecraft Player Face Rendering
Minecraft Player Face Rendering
This is actually really simple to do and can make a impressive auto-avatar to your website
[syntax=php]header('Content-Type: image/png');
$player_name = 'wide_load';
$width = 200;
$height = 200;
$cache_file = "cache/player_skins/faces/{$player_name}_{$width}x{$height}.png";
if (!file_exists($cache_file) || time() - filemtime($cache_file) > 86400){
$skin = imagecreatefromstring(file_get_contents("http://skins.minecraft.net/MinecraftSkins/{$player_name}.png"));
$face = imagecreatetruecolor($width, $height);
imagecopyresized($face, $skin, 0, 0, 8, 8, $width, $height, 8, 8);
imagecopyresized($face, $skin, 0, 0, 40, 8, $width, $height, 8, 8);
imagepng($face, $cache_file);
}
readfile($cache_file);[/syntax]
It seems pretty self-explanatory, feel free to ask questions
[syntax=php]header('Content-Type: image/png');
$player_name = 'wide_load';
$width = 200;
$height = 200;
$cache_file = "cache/player_skins/faces/{$player_name}_{$width}x{$height}.png";
if (!file_exists($cache_file) || time() - filemtime($cache_file) > 86400){
$skin = imagecreatefromstring(file_get_contents("http://skins.minecraft.net/MinecraftSkins/{$player_name}.png"));
$face = imagecreatetruecolor($width, $height);
imagecopyresized($face, $skin, 0, 0, 8, 8, $width, $height, 8, 8);
imagecopyresized($face, $skin, 0, 0, 40, 8, $width, $height, 8, 8);
imagepng($face, $cache_file);
}
readfile($cache_file);[/syntax]
It seems pretty self-explanatory, feel free to ask questions
Last edited by Helx on Thu Mar 28, 2013 9:45 am, edited 1 time in total.
Reason: Updated to play nice with migrated accounts (there's a new URL for skins)
Reason: Updated to play nice with migrated accounts (there's a new URL for skins)
Re: Minecraft Player Face Rendering
How would I use this in a MineQuery player list (like massivecraft.com)?
Sorry, I've just never used this kind of thing with an array
Sorry, I've just never used this kind of thing with an array
Re: Minecraft Player Face Rendering
You would just need to change the player_name so the name of the player you want.
Re: Minecraft Player Face Rendering
jacek wrote:You would just need to change the player_name so the name of the player you want.
Ah, thanks
Re: Minecraft Player Face Rendering
It would make the most sense to put the above code in a separate file and use a $_GET to pass in the player name
[syntax=php]$player_name = $_GET['player_name'];[/syntax]
Then you can use the script in a img tag
[syntax=xhtml]<img src="the_script.php?player_name=wide_load" alt="" />[/syntax]
then it's fully dynamic.
[syntax=php]$player_name = $_GET['player_name'];[/syntax]
Then you can use the script in a img tag
[syntax=xhtml]<img src="the_script.php?player_name=wide_load" alt="" />[/syntax]
then it's fully dynamic.
Re: Minecraft Player Face Rendering
Would it be to much trouble to ask you to explain or possibly make a video on how to put this into the Minequery script you made?
Re: Minecraft Player Face Rendering
Silent79 wrote:Would it be to much trouble to ask you to explain or possibly make a video on how to put this into the Minequery script you made?
It sort of explained above :S What don't you understand ?
Re: Minecraft Player Face Rendering
Sorry .. new to PHP ... I have been playing around with it. I think I have it figured out. Trial and error ...
Re: Minecraft Player Face Rendering
Okay You can always post in the support section if you come up with a specific question
-
- Posts: 1
- Joined: Fri Feb 10, 2012 5:21 pm
Re: Minecraft Player Face Rendering
I followed the previous tutorial(s) you did on Minequery and had incorporated that into the site I host of a Minecraft server. I was displaying the list of logged in users via [playerList], and used this code (placed inside mcface.php) to display the face instead!
[syntax=php]
foreach ($info[playerList] as $player) {
echo "<img width=\"100\" height=\"100\" src=\"/mcface.php?player_name=" . $player . "\" title=\"{$player}\" /> ";
}[/syntax]
I also incorporated this into the user profile system to auto create an avatar for any user that logs into our Minecraft server since this code creates the image, I just check if it exists and if so it displays as the users avatar. They still have an options to upload their own avatar, it's pretty neat I think...
Oh and some of the players kept asking to create a face for them to use on other sites, so I setup this form:
http://nightrebellion.com/face
It uses the same code and allows the user to generate the face and click to download...
Thanks for sharing
Re: Minecraft Player Face Rendering
Looks good ! That is pretty much what I use it for too http://somethingcraft.co.uk/player_prof ... =wide_load
Re: Minecraft Player Face Rendering
jacek wrote:Looks good ! That is pretty much what I use it for too http://somethingcraft.co.uk/player_prof ... =wide_load
May I ask how you did the MOB/player kills part? I understand that you probably used LogBlock for the blocks (because I have done that, http://s.stratuscraft.net/lb/?player=abcedea)
I know LogBlock has a player death logger, with what killed you/you killed. But I have no idea how to use that...
Re: Minecraft Player Face Rendering
abcedea wrote:May I ask how you did the MOB/player kills part? I understand that you probably used LogBlock for the blocks (because I have done that, http://s.stratuscraft.net/lb/?player=abcedea)
I know LogBlock has a player death logger, with what killed you/you killed. But I have no idea how to use that...
I found LogBlock to be a bit too slow for that kinds of stats, my database has over 8 million entries in it and summing all of those took a good few seconds. It's a custom plugin https://github.com/betterphp/PlayerStats
Re: Minecraft Player Face Rendering
jacek wrote:It's a custom plugin https://github.com/betterphp/PlayerStats
Ah, ok. I'll take a look at it.
(That explains why that webpage loaded so fast XD)
Re: Minecraft Player Face Rendering
abcedea wrote:(That explains why that webpage loaded so fast XD)
exactly ! Since we have 8 worlds on the server it used to take a good 30 seconds sometimes to load !
Re: Minecraft Player Face Rendering
jacek wrote:Looks good ! That is pretty much what I use it for too http://somethingcraft.co.uk/player_prof ... =wide_load
Sorry to bring back an old thread, but how the hell did you break Air blocks!?!?!
http://i.imgur.com/APYmk.png
Re: Minecraft Player Face Rendering
jobud9 wrote:how the hell did you break Air blocks!?!?!
I would imagine superpick or some kind of black magic :/
Re: Minecraft Player Face Rendering
abcedea wrote:jobud9 wrote:how the hell did you break Air blocks!?!?!
I would imagine superpick or some kind of black magic :/
Yep, or bugs. Or I think placing water buckets. I should filter them out really
Re: Minecraft Player Face Rendering
Oh boy, sorry for reviving an old thread but I could use some help with this script. Im doing my best with my very very very basic understanding of php to incorporate this in to my sites CMS(php-fusion) for users auto avatars. Also excuse me if I misuse the terminology here. Upon registering a user has to input their username in order to register. So I have your code. [syntax=php]<?php
header('Content-Type: image/png');
$user_minecraft = 'wide_load';
$width = 100;
$height = 100;
$cache_file = "player_skins/{$user_minecraft}_{$width}x{$height}.png";
if (!file_exists($cache_file) || time() - filemtime($cache_file) > 86400){
$skin = imagecreatefromstring(file_get_contents("http://s3.amazonaws.com/MinecraftSkins/{$user_minecraft}.png"));
$face = imagecreatetruecolor($width, $height);
imagecopyresized($face, $skin, 0, 0, 8, 8, $width, $height, 8, 8);
imagecopyresized($face, $skin, 0, 0, 40, 8, $width, $height, 8, 8);
imagepng($face, $cache_file);
}
readfile($cache_file);
?>[/syntax]
My issue here is that 'wide_load' needs to call from the db query for a players username
The dq query for this is [syntax=php]".$data['user_minecraft'].">[/syntax]
I need to somehow make these files work with each other so that I can replace all the avatar code to this.
Heres what im using to test it at least [syntax=php]echo "<img src=h.../mcavatar.php?player_name=".$data['user_minecraft'].">\n";[/syntax] The script runs fine and will load the player face of "wide_load"
In addition I also need a if/else for an invalid username say its unable to load an image then else it would load like a noavatar.png image.
I hope you understand what im trying to get it as im having trouble explaining this without knowing all the terms. Thanks in advance!
header('Content-Type: image/png');
$user_minecraft = 'wide_load';
$width = 100;
$height = 100;
$cache_file = "player_skins/{$user_minecraft}_{$width}x{$height}.png";
if (!file_exists($cache_file) || time() - filemtime($cache_file) > 86400){
$skin = imagecreatefromstring(file_get_contents("http://s3.amazonaws.com/MinecraftSkins/{$user_minecraft}.png"));
$face = imagecreatetruecolor($width, $height);
imagecopyresized($face, $skin, 0, 0, 8, 8, $width, $height, 8, 8);
imagecopyresized($face, $skin, 0, 0, 40, 8, $width, $height, 8, 8);
imagepng($face, $cache_file);
}
readfile($cache_file);
?>[/syntax]
My issue here is that 'wide_load' needs to call from the db query for a players username
The dq query for this is [syntax=php]".$data['user_minecraft'].">[/syntax]
I need to somehow make these files work with each other so that I can replace all the avatar code to this.
Heres what im using to test it at least [syntax=php]echo "<img src=h.../mcavatar.php?player_name=".$data['user_minecraft'].">\n";[/syntax] The script runs fine and will load the player face of "wide_load"
In addition I also need a if/else for an invalid username say its unable to load an image then else it would load like a noavatar.png image.
I hope you understand what im trying to get it as im having trouble explaining this without knowing all the terms. Thanks in advance!
Re: Minecraft Player Face Rendering
If you have ?player_name=something in the URL you can get that value in the code using $_GET so for this it would be $_GET['player_name']
So just
[syntax=php]$user_minecraft = $_GET['player'_name'];[/syntax]
should do it.
So just
[syntax=php]$user_minecraft = $_GET['player'_name'];[/syntax]
should do it.