public/index.php aktualisiert
All checks were successful
release-tag / release-image (push) Successful in 26s

This commit is contained in:
2025-01-01 23:02:44 +00:00
parent 72e7158aa3
commit 8d180466a2

View File

@@ -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[]