diff --git a/index.php b/index.php index 7ae8c07..034832a 100644 --- a/index.php +++ b/index.php @@ -1,43 +1,49 @@ download_url; + header("Location: $random_image_path"); } +// 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]; + header("Location: $image_path"); +} ?> @@ -175,9 +181,9 @@ if (isset($_GET['random'])) { @@ -191,7 +197,7 @@ if (isset($_GET['random'])) { window.addEventListener("load", function() { /** * Open image based on hash - * + * * If the hash is "gallery", open the first image in the gallery, * otherwise, open the image with the hash as the alt attribute. */ @@ -207,6 +213,21 @@ if (isset($_GET['random'])) { // initialize glightbox const lightbox = GLightbox(); + // add image dimensions to description on image load + lightbox.on("slide_after_load", function(slide) { + // get the dimensions of the slide image + const image = slide.slide.querySelector("img"); + const width = image.naturalWidth; + const height = image.naturalHeight; + // get the description and add the dimensions if not already present + const description = slide.slideConfig.description; + const parts = description.split(" • "); + parts[1] = ` ${width}x${height}`; + slide.slideConfig.description = parts.join(" • "); + // update the description + slide.slide.querySelector(".gslide-desc").innerText = slide.slideConfig.description; + }); + // add hash to url when image is opened lightbox.on("slide_changed", function(slide) { window.location.hash = slide.current.slideConfig.alt;