public/index.php aktualisiert
All checks were successful
release-tag / release-image (push) Successful in 26s
All checks were successful
release-tag / release-image (push) Successful in 26s
This commit is contained in:
@@ -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[]
|
||||
|
Reference in New Issue
Block a user