Last active
May 6, 2016 06:55
-
-
Save shoghicp/5388824 to your computer and use it in GitHub Desktop.
Draw a Canvas of a Minecraft skin, with the hat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2004 Sam Hocevar <[email protected]> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. | |
*/ | |
function getMCHead($player, $width = 64){ | |
$name = preg_replace("#[^A-Za-z0-9_]*#", "", $player); | |
$id = "b".mt_rand(); | |
$width = (int) $width; | |
return '<canvas title="'.$name.'" height="'.$width.'" width="'.$width.'" id ="'.$id.'" style="border-radius:'.ceil(0.075 * $width).'px;padding:'.ceil(0.03125 * $width).'px;image-rendering:-moz-crisp-edges;image-rendering:-o-crisp-edges;image-rendering:-webkit-optimize-contrast;image-rendering:crisp-edges;-ms-interpolation-mode: nearest-neighbor;"></canvas><script type="text/javascript">var img'.$id.'=new Image();img'.$id.'.src="http://s3.amazonaws.com/MinecraftSkins/'.$name.'.png";img'.$id.'.onload=function(){var ctx=document.getElementById("'.$id.'").getContext("2d");ctx.imageSmoothingEnabled=false;ctx.webkitImageSmoothingEnabled=false;ctx.mozImageSmoothingEnabled = false;ctx.drawImage(img'.$id.', 8, 8, 8, 8, 0, 0, '.$width.', '.$width.');ctx.drawImage(img'.$id.', 40, 8, 8, 8, 0, 0, '.$width.', '.$width.');};</script>'; | |
} | |
echo getMCHead("shoghicp"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment