1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-12-10 07:42:29 +03:00

Images: Made resize errors log with error detail

Closes #5869
This commit is contained in:
Dan Brown
2025-12-07 12:54:57 +00:00
parent 34e747162f
commit 08e7ba7064

View File

@@ -55,7 +55,7 @@ class ImageResizer
/**
* Get the thumbnail for an image.
* If $keepRatio is true only the width will be used.
* If $keepRatio is true, only the width will be used.
* Checks the cache then storage to avoid creating / accessing the filesystem on every check.
*
* @throws Exception
@@ -84,7 +84,7 @@ class ImageResizer
return $this->storage->getPublicUrl($cachedThumbPath);
}
// If thumbnail has already been generated, serve that and cache path
// If a thumbnail has already been generated, serve that and cache path
$disk = $this->storage->getDisk($image->type);
if (!$shouldCreate && $disk->exists($thumbFilePath)) {
Cache::put($thumbCacheKey, $thumbFilePath, static::THUMBNAIL_CACHE_TIME);
@@ -110,7 +110,7 @@ class ImageResizer
}
/**
* Resize the image of given data to the specified size, and return the new image data.
* Resize the image of given data to the specified size and return the new image data.
* Format will remain the same as the input format, unless specified.
*
* @throws ImageUploadException
@@ -125,6 +125,7 @@ class ImageResizer
try {
$thumb = $this->interventionFromImageData($imageData, $format);
} catch (Exception $e) {
Log::error('Failed to resize image with error:' . $e->getMessage());
throw new ImageUploadException(trans('errors.cannot_create_thumbs'));
}
@@ -154,17 +155,21 @@ class ImageResizer
/**
* Create an intervention image instance from the given image data.
* Performs some manual library usage to ensure image is specifically loaded
* Performs some manual library usage to ensure the image is specifically loaded
* from given binary data instead of data being misinterpreted.
*/
protected function interventionFromImageData(string $imageData, ?string $fileType): InterventionImage
{
if (!extension_loaded('gd')) {
throw new ImageUploadException('The PHP "gd" extension is required to resize images, but is missing.');
}
$manager = new ImageManager(
new Driver(),
autoOrientation: false,
);
// Ensure gif images are decoded natively instead of deferring to intervention GIF
// Ensure GIF images are decoded natively instead of deferring to intervention GIF
// handling since we don't need the added animation support.
$isGif = $fileType === 'gif';
$decoder = $isGif ? NativeObjectDecoder::class : BinaryImageDecoder::class;
@@ -223,7 +228,7 @@ class ImageResizer
}
/**
* Checks if the image is a gif. Returns true if it is, else false.
* Checks if the image is a GIF. Returns true if it is, else false.
*/
protected function isGif(Image $image): bool
{
@@ -250,7 +255,7 @@ class ImageResizer
/**
* Check if the given avif image data represents an animated image.
* This is based up the answer here: https://stackoverflow.com/a/79457313
* This is based upon the answer here: https://stackoverflow.com/a/79457313
*/
protected function isAnimatedAvifData(string &$imageData): bool
{