* * @author https://github.com/jamiebicknell/Minecraft-Avatar/blob/master/face.php * @param string $hash * @param int $size * @param string $view, default for 'f' * @return resource */ public static function generateAvatarFromSkin($hash, $size, $view='f') { $src = imagecreatefrompng(BASE_DIR."/textures/$hash"); $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; } /** * Check if given texture is occupied * * @param string $hash * @return bool */ public static function checkTextureOccupied($hash) { $db = new Database\Database('users'); if ($db->getNumRows('hash_steve', $hash) > 1) { return true; } elseif ($db->getNumRows('hash_alex', $hash) > 1) { return true; } elseif ($db->getNumRows('hash_cape', $hash) > 1) { return true; } // finally if given texture is not used by anyone else return false; } /** * Generate random string * * @param int $length * @return string */ public static function generateRndString($length) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|'; $rnd_string = ''; for ($i = 0; $i < $length; $i++) { $rnd_string .= $chars[mt_rand(0, strlen($chars) - 1)]; } return $rnd_string; } /** * HTTP redirect * * @param string $url * @return null */ public static function redirect($url) { header('Location: '.$url); } }