I’m so not a gamer, but over the weekend I got the fun chance to record an episode of The Pixel Shadow with me as host. Continue reading
Category Archives: Gaming
Convert Minecraft 1.8+ Skin to 1.6/1.7/Minetest Skin in PHP
As we build up #ThePixelShadow on Category5 TV, and introduce a creative Minetest server specifically for playing Minetest (the free Minecraft alternative), it became apparent that our users/viewers would like to be able to have their own custom skins.
We’re making it easy with a nice little interface to upload your own skins, but part of the process requires making a skin which is compatible with sdzen’s/PilzAdam’s player_textures mod … basically, these skins are Minecraft 1.6/1.7 skins… 64×32. Great Minecraft skin creator sites such as minecraftskins.com now generate Minecraft 1.8 skin files, which are 64×64.
The difference is essentially that the skins now support overlays (eg., removable headphones or glasses) and your left and right arms and legs can have different textures. Not the case with 1.6/1.7/Minetest… so we must convert the skin file to make it compatible.
Since we’re building a web interface to do this all automatically for you and place your player skin on our server automatically, I’m building the program in PHP. Since there are a lot of tutorials out there that simply instruct you to change your canvas size to 64×32 (which is wrong – you will lose your overlays!) I thought I would share my method with you in case it comes in handy.
And hey, it’s a fun exercise in PHP/GD anyways 🙂
<?php // Convert Minecraft 1.8+ skin to 1.7-/Minetest skin. // From Robbie Ferguson // www.baldnerd.com // Requires PHP, GD // By default outputs png to browser window AND saves a file for future use. Edit below to change behaviour. // v1.1 $input = './uploads/player_RobbieF.png'; // your 1.8 skin file $output = 'newskin.png'; // your new 1.7/Minetest skin file // Create image instances $src = imagecreatefrompng($input); $dest = imagecreatetruecolor(64, 32); // Make it transparent imagesavealpha($dest, true); $trans_colour = imagecolorallocatealpha($dest, 0, 0, 0, 127); imagefill($dest, 0, 0, $trans_colour); // Learn the dimensions of the input image $size = getimagesize($input); if ($size[0] == 64 && $size[1] == 64) { // it has Minecraft 1.8 skin dimensions - convert! // Copy - Syntax is Dest X,Y, Source X,Y, Width,Height // Head imagecopy($dest, $src, 0,0, 0,0, 32,16); // Head overlay imagecopy($dest, $src, 0,0, 32,0, 32,16); // Right leg, Body, Right Arm // The Leg and Arm become both left and right in 1.7- // We'll simply discard the left arm and leg since it's not used. // If you have an overlay on your left arm/leg but not right arm/leg, you might want to edit your skin since that will be discarded. imagecopy($dest, $src, 0,16, 0,16, 64,16); // Leg, Body and Arm overlay imagecopy($dest, $src, 0,16, 0,32, 64,16); } else { // already compatible. Just copy it. imagecopy($dest, $src, 0,0, 0,0, 64,32); } // Output to browser header('Content-Type: image/png'); imagepng($dest); // Save to a file imagepng($dest,$output,0); // 0-9. 0=faster, 9=smaller. // Free up memory imagedestroy($dest); imagedestroy($src); ?>
If you find a good use for it in your project, please comment below. If you really love what I do, please consider supporting my Patreon profile, or throw a little something in the tip jar.
Hope to see you on #ThePixelShadow Minetest server soon, custom skin and all!
-Robbie