Skip to content

Instantly share code, notes, and snippets.

@shoghicp
Last active May 6, 2016 06:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoghicp/5388824 to your computer and use it in GitHub Desktop.
Save shoghicp/5388824 to your computer and use it in GitHub Desktop.
Draw a Canvas of a Minecraft skin, with the hat.
<?php
/*
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
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