Here's how we do it, in case it helps you out... and now, I must review for any security holes - lol!
Don't use it verbatim (as it likely won't work for you as is -- you're missing some of our components), but glean ideas or help from it if you like.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
<?php
require_once('./includes/header.php');
$gallery['folder'] = '/home/robbie/minetest.tv/skins/uploads/';
if(isset($_FILES['file']) && strlen(trim(strip_tags($_POST['username']))) > 0 ) {
$username = trim(strip_tags($_POST['username']));
$target_dir = '/tmp/';
$target_file = $target_dir . basename($_FILES['file']['name']);
$uploadOk = 1;
$extension = pathinfo($target_file,PATHINFO_EXTENSION);
if ($extension == 'png') {
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES['file']['tmp_name']);
if($check !== false) {
$input = $_FILES['file']['tmp_name'];
$skin['filename'] = 'player_' . $username . '.png';
$skin['datestamp'] = date('U'); // fake it :)
$skin['username'] = $username;
$output = $gallery['folder'] . $skin['filename'];
if (!file_exists($output)) {
// 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);
$uploadOk = 1;
} else {
$error = 'That user already has a skin. If you\'d like to overwrite it, please contact us.';
$uploadOk = 0;
}
} else {
$error = 'Invalid File.';
$uploadOk = 0;
unlink($_FILES['file']['tmp_name']);
}
} else {
$error = 'Invalid File.';
}
}
?>
<div class="container">
<div class="col-sm-12">
<?= responsivead(1,0) ?>
<div class="caption text-center">
<p>Advertisement</p>
</div>
</div>
</div>
<div class="container">
<div class="col-md-8">
<form class="sky-form" method="post" enctype="multipart/form-data">
<header>Skin Converter</header>
<p>Convert your Minecraft 1.8 Skin into Minecraft 1.6/1.7/Minetest format</p>
<p>Please login to our server first to ensure your name is available and create your account, then convert your skin using the exact same name you use to login (case-sensitive). Your new skin will be available immediately in the <span class="text-highlights text-highlights-green rounded"><a href="./skins.php">Minetest Skin Gallery</a></span> for you to download to use on any Minetest server (or your own local games) and will also be automatically synced to your account on our servers within a couple hours.</p>
<p>Don't have a skin? Try downloading or creating one via <span class="text-highlights text-highlights-green rounded"><a href="http://www.minecraftskins.com/" target="_blank">The Skindex</a></span> and then use our system to convert and import it to Minetest.</p>
<p><b>Please Note:</b> Your skin is your visual identity to other players on our servers. Plan out your skin and make sure you're happy with it before you use the converter as you cannot change it once it is synced. That said, if you experience a problem or require help, please contact an admin in-game.</p>
<?php
if ($uploadOk == 1) {
$gallery['output'] = '';
$gallery['output'] .= '<div class="container team-v1 content-sm">
<div class="margin-bottom-40 text-center">
<h2 class="title-v2 title-center">YOUR CONVERTED SKIN</h2>
<p>All done!</p>
</div>
<ul class="list-unstyled row">';
$gallery['output'] .= '<li class="col-sm-2 col-xs-4 md-margin-bottom-30">
<div class="team-img text-center">
<img class="img-responsive" style="margin: 0 auto;" src="./skins/preview/front/' . $skin['username'] . '.png" alt="">
<ul>
<li class="text-center"><a target="_blank" href="/skins/uploads/' . $skin['filename'] . '"><i class="icon-custom icon-sm rounded-x fa fa-download"></i></a></li>
</ul>
</div>
<h3 class="text-center">' . $skin['username'] . '</h3>
<h4 class="text-center">' . date('F j, Y', $skin['datestamp']) . '</h4>
</li>' . PHP_EOL;
$gallery['output'] .= '</ul></div>';
echo $gallery['output'];
}
if (isset($error)) {
echo '<p class="bg-danger">' . $error . '</p>';
}
?>
<fieldset>
<section style="display:none;">
<label class="label">Convert and...</label>
<div class="row">
<div class="col col-6">
<h1>Free Options</h1>
<label class="checkbox"><input type="checkbox" name="checkbox" checked disabled><i></i>Show Sample In Skin Gallery</label>
<label class="checkbox"><input type="checkbox" name="checkbox" checked><i></i>Allow Other Users to Download Skin File</label>
<label class="checkbox"><input type="checkbox" name="checkbox"><i></i>Sync To My Minetest.TV Player Account</label>
</div>
<div class="col col-6">
<h1>Paid Options (We Accept PayPal)</h1>
<label class="checkbox"><input type="checkbox" name="checkbox"><i></i>Output HD Skin ($1)</label>
<label class="checkbox"><input type="checkbox" name="checkbox"><i></i>Give Me a JPG Too ($1)</label>
</div>
</div>
</section>
<section>
<label class="label">Your Username</label>
<label class="input">
<input type="text" name="username">
</label>
</section>
<section>
<label class="label">File input</label>
<label for="file" class="input input-file">
<div class="button"><input type="file" id="file" onchange="this.parentNode.nextSibling.value = this.value" name="file">Browse</div><input type="text" readonly>
</label>
</section>
</fieldset>
<footer>
<button type="submit" class="btn-u">Submit</button>
<button type="button" class="btn-u btn-u-default" onclick="window.history.back();">Back</button>
</footer>
</form>
</div>
<div class="col-md-4">
<?= responsivead(3,0) ?>
</div>
</div>
<div class="container">
<div class="col-sm-12">
<?= responsivead(2,0) ?>
<div class="caption text-center">
<p>Advertisement</p>
</div>
</div>
</div>
<?php
echo responsivead(0,1); // initialize the page's ads
require_once('./includes/footer.php');
?>
Of course, "./skins/preview/front/' . $skin['username'] . '.png" doesn't actually exist. It's a render created by another script, which I'm also happy to share if you want. Perhaps I could add this stuff to GitHub.
Robbie
#ThePixelShadow on YouTubeA Weekly Minetest Webcast hosted by MangleFox70
Have a mod you'd like featured? Want to participate in our show? Join
servers.minetest.tv Port 30000 for creative or 30001 for survival.
Upload your own skin via our web site:
Minetest.TV