4500000) { header("Location: $url"); exit; } // set content type if (preg_match("/\.(jpg|jpeg)$/", $url)) { header('Content-Type: image/jpeg'); } elseif (preg_match("/\.(png)$/", $url)) { header('Content-Type: image/png'); } elseif (preg_match("/\.(gif)$/", $url)) { header('Content-Type: image/gif'); } // set default filename header('Content-Disposition: inline; filename="' . basename($url) . '"'); // output the image exit($contents); } $REPO = "DenverCoder1/minimalistic-wallpaper-collection"; $BRANCH_NAME = "main"; $IMAGES_DIRECTORY = "images"; $BASE_URL = "https://raw.githubusercontent.com/$REPO/$BRANCH_NAME/$IMAGES_DIRECTORY/"; // prefix for generating 332x200px thumbnails $IMGPROXY_PREFIX = "https://dc1imgproxy.fly.dev/x/rs:auto:332:200:1/plain/" . urlencode($BASE_URL); // API url to get a listing of images in the directory on GitHub $GITHUB_API_URL = "https://api.github.com/repos/$REPO/contents/$IMAGES_DIRECTORY/"; // whether to force a redirect to the image instead of displaying it directly $redirect = isset($_GET['redirect']) ? $_GET['redirect'] === "1" : false; // if the current URL is in the form "/images/...", show the image if (preg_match("/\/images\/(.*)$/", $_SERVER['REQUEST_URI'], $matches)) { $image_path = $BASE_URL . $matches[1]; displayImage($image_path, $REPO, $redirect); } // fetch the list of images from GitHub $images = json_decode(curlGetContents($GITHUB_API_URL, $REPO), true); // if the random query string parameter is set, pick a random image if (isset($_GET['random'])) { // get the image url $random_image_path = $images[array_rand($images)]["download_url"]; displayImage($random_image_path, $REPO, $redirect); } ?>