public static function generateAvatarFromSkin($resource, $size, $view = 'f', $base64 = false)
{
$src = $base64 ? imagecreatefromstring(base64_decode($resource)) : imagecreatefrompng($resource);
$dest = imagecreatetruecolor($size, $size);
$ratio = imagesx($src) / 64;
// width/64
// f => front, l => left, r => right, b => back
$x = array('f' => 8, 'l' => 16, 'r' => 0, 'b' => 24);
imagecopyresized($dest, $src, 0, 0, $x[$view] * $ratio, 8 * $ratio, $size, $size, 8 * $ratio, 8 * $ratio);
// Face
imagecolortransparent($src, imagecolorat($src, 63 * $ratio, 0));
// Black Hat Issue
imagecopyresized($dest, $src, 0, 0, ($x[$view] + 32) * $ratio, 8 * $ratio, $size, $size, 8 * $ratio, 8 * $ratio);
// Accessories
imagedestroy($src);
return $dest;
}