Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions app/Uploads/ImageResizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function loadGalleryThumbnailsForImage(Image $image, bool $shouldCreate):

/**
* 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
Expand Down Expand Up @@ -84,7 +84,7 @@ public function resizeToThumbnailUrl(
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);
Expand All @@ -110,7 +110,7 @@ public function resizeToThumbnailUrl(
}

/**
* 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
Expand All @@ -125,6 +125,7 @@ public function resizeImageData(
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'));
}

Expand Down Expand Up @@ -154,17 +155,21 @@ public function resizeImageData(

/**
* 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;
Expand Down Expand Up @@ -223,7 +228,7 @@ protected function orientImageToOriginalExif(InterventionImage $image, string $o
}

/**
* 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
{
Expand All @@ -250,7 +255,7 @@ protected function isApngData(string &$imageData): bool

/**
* 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
{
Expand Down
4 changes: 3 additions & 1 deletion resources/sass/_lists.scss
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,10 @@ details.sort-box[open] summary .caret-container svg {

ul.pagination {
display: inline-flex;
flex-wrap: wrap;
list-style: none;
margin: vars.$m 0;
padding-inline-start: 1px;
padding-inline: 1px;
li:first-child {
a, span {
border-radius: 3px 0 0 3px;
Expand All @@ -384,6 +385,7 @@ ul.pagination {
padding: vars.$xxs vars.$s;
border: 1px solid #CCC;
margin-inline-start: -1px;
margin-block-end: -1px;
user-select: none;
@include mixins.lightDark(color, #555, #eee);
@include mixins.lightDark(border-color, #ccc, #666);
Expand Down