From 8d180466a203915d3657f75bcfd49505b2fb432f Mon Sep 17 00:00:00 2001 From: groot Date: Wed, 1 Jan 2025 23:02:44 +0000 Subject: [PATCH] public/index.php aktualisiert --- public/index.php | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/public/index.php b/public/index.php index 80c8d21..a0a29b7 100644 --- a/public/index.php +++ b/public/index.php @@ -68,6 +68,23 @@ function getCategories(): array { /** * Get the thumbnail image uri for the given category. */ + +function getCategoryThumbnail(string $category): string { + $categoryImages = getCategoryImageFiles($category); + $firstImage = $categoryImages[0] ?? ''; + if (empty($firstImage)) { + return ''; + } + + generateImageThumbnail($category, $firstImage); + return "thumbs/{$category}/{$firstImage}"; +} + +/** + * Generated a thumbnail for the given image filename withing + * the given category folder. + */ + function generateImageThumbnail(string $category, string $image): void { $imagePath = buildPath(IMAGES_DIR, $category, $image); $thumbPath = buildPath(THUMBS_DIR, $category, $image); @@ -121,36 +138,6 @@ function generateImageThumbnail(string $category, string $image): void { imagedestroy($thumbImage); } -/** - * Generated a thumbnail for the given image filename withing - * the given category folder. - */ -function generateImageThumbnail(string $category, string $image): void { - $imagePath = buildPath(IMAGES_DIR, $category, $image); - $thumbPath = buildPath(THUMBS_DIR, $category, $image); - - if (file_exists($thumbPath)) { - return; - } - - if (!file_exists($imagePath)) { - error("Could not find image at {$imagePath}"); - } - - if (!str_ends_with(strtolower($imagePath), '.webp')) { - error("Image at {$imagePath} is not webp as expected"); - } - - $thumbDir = dirname($thumbPath); - if (!file_exists($thumbDir)) { - mkdir($thumbDir); - } - - $originalImage = imagecreatefromwebp($imagePath); - $thumbImage = imagescale($originalImage, 1200); - imagewebp($thumbImage, $thumbPath, 50); -} - /** * Get the categorized folder names within the image directory. * @return string[]