$width = $request->param('width', 1024); $height = $request->param('height', 768); $files = Minotar::getFilesFromDir("./minecraft/heads"); if ($width >= 1920) { $width = 1920; } if ($height >= 1080) { $height = 1080; } $files = array_slice($files, 500); //list($width, $height) = getimagesize($_GET['image']); $image_p = imagecreatetruecolor($width, $height); $count = 1; foreach ($files as $avatar) { $image = imagecreatefrompng($avatar); imagecopyresampled($image_p, $image, $width * $count, $height * $count, 0, 0, $width, $height, 42, 42); $count++; } header('Content-type: image/png'); imagejpeg($image_p, null, 100); }); respond('/refresh/[:username]', function ($request, $response) { $username = $request->param('username'); $name = Minotar::get($username, true); Header("Location: " . URL . "avatar/{$username}"); }); respond('404', function ($request, $response) { $response->layout('html/template/default.php'); $response->render('html/404.php', array("title" => "404")); }); dispatch();
/** * Gets the files from a directory * * @param $dir * @return array */ public static function getFilesFromDir($dir) { $files = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "Thumbs.db") { if (is_dir($dir . '/' . $file)) { $dir2 = $dir . '/' . $file; $files[] = getFilesFromDir($dir2); } else { $files[] = $dir . '/' . $file; } } } closedir($handle); } return Minotar::array_flat($files); }
}); respond('/skin/[:username]', function ($request, $response) { $name = $request->param('username', 'char'); $name = Minotar::get($name); $img = WideImage::load("./minecraft/skins/{$name}.png"); $img->output('.png'); }); respond('/all/[:type]?', function ($request, $response) { $type = $request->param('type', 'heads'); $files = Minotar::getFilesFromDir("./minecraft/{$type}"); $response->render('html/all.phtml', array('files' => $files)); }); respond('/wallpaper/[:width]/[:height]?', function ($request, $response) { $width = $request->param('width', 1024); $height = $request->param('height', 768); $files = Minotar::getFilesFromDir("./minecraft/heads"); if ($width >= 1920) { $width = 1920; } if ($height >= 1080) { $height = 1080; } $files = array_slice($files, 500); //list($width, $height) = getimagesize($_GET['image']); $image_p = imagecreatetruecolor($width, $height); $count = 1; foreach ($files as $avatar) { $image = imagecreatefrompng($avatar); imagecopyresampled($image_p, $image, $width * $count, $height * $count, 0, 0, $width, $height, 42, 42); $count++; }