From 27b715cb35dc048e5cf5628529dc7aa987f5e847 Mon Sep 17 00:00:00 2001 From: Jonathan <54287723+inthreedee@users.noreply.github.com> Date: Mon, 3 Jan 2022 17:46:10 -0500 Subject: [PATCH 1/2] Avoid upscaling small images --- app/Util/Media/Image.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Util/Media/Image.php b/app/Util/Media/Image.php index cbc1efe67..dc6608c08 100644 --- a/app/Util/Media/Image.php +++ b/app/Util/Media/Image.php @@ -72,6 +72,8 @@ class Image return [ 'dimensions' => $this->orientations()[$orientation], 'orientation' => $orientation, + 'width_original' => $width, + 'height_original' => $height, ]; } @@ -157,9 +159,11 @@ class Image $media->metadata = json_encode($meta); } - $img->resize($aspect['width'], $aspect['height'], function ($constraint) { - $constraint->aspectRatio(); - }); + if ( ($ratio['width_original'] > $aspect['width']) || ($ratio['height_original'] > $aspect['height']) ) { + $img->resize($aspect['width'], $aspect['height'], function ($constraint) { + $constraint->aspectRatio(); + }); + } } $converted = $this->setBaseName($path, $thumbnail, $img->extension); $newPath = storage_path('app/'.$converted['path']); From c43f9ab7a497135ecd575d2d70b7096c0dd901e8 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 5 Jan 2022 18:36:02 -0700 Subject: [PATCH 2/2] Update app/Util/Media/Image.php Co-authored-by: Daniel Mason --- app/Util/Media/Image.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Util/Media/Image.php b/app/Util/Media/Image.php index dc6608c08..9048fbc31 100644 --- a/app/Util/Media/Image.php +++ b/app/Util/Media/Image.php @@ -159,7 +159,10 @@ class Image $media->metadata = json_encode($meta); } - if ( ($ratio['width_original'] > $aspect['width']) || ($ratio['height_original'] > $aspect['height']) ) { + if ( + ($ratio['width_original'] > $aspect['width']) + || ($ratio['height_original'] > $aspect['height']) + ) { $img->resize($aspect['width'], $aspect['height'], function ($constraint) { $constraint->aspectRatio(); });