Page 1 of 1
Minecraft Player Face Rendering
Posted: Mon Jun 11, 2012 5:11 pm
by jacek
This is actually really simple to do and can make a impressive auto-avatar to your website
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/MinecraftSki ... _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);
It seems pretty self-explanatory, feel free to ask questions
Re: Minecraft Player Face Rendering
Posted: Wed Jun 20, 2012 9:02 am
by Helx
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
Re: Minecraft Player Face Rendering
Posted: Wed Jun 20, 2012 11:09 am
by jacek
You would just need to change the player_name so the name of the player you want.
Re: Minecraft Player Face Rendering
Posted: Wed Jun 20, 2012 11:26 am
by Helx
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
Posted: Wed Jun 20, 2012 11:32 am
by jacek
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
$player_name = $_GET['player_name'];
Then you can use the script in a img tag
<img src="the_script.php?player_name=wide_load" alt="" />
then it's fully dynamic.
Re: Minecraft Player Face Rendering
Posted: Thu Jun 21, 2012 8:43 pm
by Silent79
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
Posted: Thu Jun 21, 2012 9:14 pm
by jacek
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
Posted: Thu Jun 21, 2012 9:56 pm
by Silent79
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
Posted: Thu Jun 21, 2012 10:32 pm
by jacek
Okay
You can always post in the support section if you come up with a specific question
Re: Minecraft Player Face Rendering
Posted: Thu Jun 28, 2012 6:50 pm
by someonetech
- screenshot of logged in user faces
- Screen Shot 2012-06-27 at 4.23.31 PM.png (188.94 KiB) Viewed 12481 times
This is totally cool...
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!
foreach ($info[playerList] as $player) {
echo "<img width=\"100\" height=\"100\" src=\"/mcface.php?player_name=" . $player . "\" title=\"{$player}\" /> ";
}
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
Posted: Fri Jun 29, 2012 12:50 pm
by jacek
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
Posted: Fri Jun 29, 2012 9:48 pm
by Helx
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
Posted: Fri Jun 29, 2012 10:13 pm
by jacek
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
Posted: Fri Jun 29, 2012 10:37 pm
by Helx
Ah, ok. I'll take a look at it.
(That explains why that webpage loaded so fast XD)
Re: Minecraft Player Face Rendering
Posted: Sat Jun 30, 2012 12:18 am
by jacek
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
Posted: Sun Jul 08, 2012 11:19 am
by jobud9
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
Posted: Sun Jul 08, 2012 8:52 pm
by Helx
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
Posted: Sun Jul 08, 2012 10:37 pm
by jacek
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
Posted: Mon Jan 21, 2013 4:03 am
by Brotaoski
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.
<?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/ ... craft}.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);
?>
My issue here is that 'wide_load' needs to call from the db query for a players username
The dq query for this is
".$data['user_minecraft'].">
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
echo "<img src=h.../mcavatar.php?player_name=".$data['user_minecraft'].">\n";
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
Posted: Tue Jan 29, 2013 7:29 am
by jacek
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
$user_minecraft = $_GET['player'_name'];
should do it.