Merge pull request #3121 from inthreedee/patch-1

Avoid upscaling small images
This commit is contained in:
daniel 2022-01-05 18:37:13 -07:00 committed by GitHub
commit 854f858543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -72,6 +72,8 @@ class Image
return [
'dimensions' => $this->orientations()[$orientation],
'orientation' => $orientation,
'width_original' => $width,
'height_original' => $height,
];
}
@ -157,9 +159,14 @@ 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']);