Minecraft Avatar via PHP

Here's a little something I built for fun a while back, when I was more active on Minecraft. I wanted a real simple way to generate a user's Minecraft avatar from their skin, and be able to display at any size.

Minecraft Avatar

It's as easy as this to use:

<img src='face.php?u={username}&s={size}' />

What the script does is grabs their skin from the Minecraft server, copies the face and facial accessories only and merges them into an 8 x 8 image, then resizes to the specified size. If the username does not exist, then it uses the default skin, which is stored in a base64 encoded variable to save an extra cURL request.

Check out the code on Github

John

John wrote:

Why does the avatar become black when using Notch for example as username?

Jamie Bicknell

Jamie Bicknell wrote:

@John, it seems that with Notch's skin, the part for the facial accessories is just black. When I built the script facial accessories were part of the skin, but I think maybe now it's changed so that they are excluded. Will have to boot up Minecraft and do some tested.

Also, on quite a few online skin editors, Notch's face appears black too, so I think it's maybe the fact that the skin sections have changed at some time, but the scripts haven't been updated.

John

John wrote:

Yes, I have discovered that on multiple skin scripts some skins appear black/dark colored. It would be very nice of you if you update this to work for the current Minecraft. I know many people would appreciate such tool. I know there are Minotar, Achievecraft etc but they don't offer the same type of freedom when coding.

Jamie Bicknell

Jamie Bicknell wrote:

Just comment out line 32, where it adds the facial accessories.

I'm not going to update the script just yet until I get 100% confirmation that facial accessories have been removed from the skins, but I'll be looking into it.

Jamie Bicknell

Jamie Bicknell wrote:

It appears that if the entire 8x8 block for the facial accessories is black, then it treats it as transparent in-game. However this is not documented anywhere, and should really be transparent if not needed.

I think this only leaves one option, which is to do a check in the script if the facial accessories is pure black, and if so, treat it as transparent.

Jamie Bicknell

Jamie Bicknell wrote:

I've done some further testing, and if you use Notch's skin as a default, no matter what you put in the facial accessories block it will always appear as transparent. This means there is something else controlling the transparency of that particular section.

There is no way for me to tell what this additional check is, and what will all the other online editors showing as a black, there really isn't anything I can do.

As a result, I'll be leaving my code as it is. I can only assume Notch's skin hasn't been updated for a while, and there is some kind of legacy code built in so accommodate it.

John

John wrote:

Alright. I commented line 32 as you said and now it works. I appreciate your help! I think this is a really good base, I'll be trying to work on getting full skins appear too unless you plan on adding more features of course. ;) No pressure. Great script!

Jamie Bicknell

Jamie Bicknell wrote:

I won't be adding full body skins, it was only ever meant to be for avatars for forums, blogs, comments etc.

Jamie Bicknell

Jamie Bicknell wrote:

Hi John,

I've found the issue to be called the 'Black Hat' issue, and I've added a fix for it to my code, you can grab the latest version here.

What this does is takes the colour of the top right pixel, and uses this as the transparency.

Thanks for bringing this issue to my attention, and thanks for being patient whilst I find and fix it.

John

John wrote:

Alright, I understand. I'll try get the full body part to work myself.

And that's awesome. Going to update my script with yours.

Thanks a lot yourself!

Gravatar
  • (optional)
  • Security Code