1
0
Fork 0
forked from mirror/pixelfed

Avoid upscaling small images

This commit is contained in:
Jonathan 2022-01-03 17:46:10 -05:00 committed by GitHub
parent 5fc83beb2c
commit 27b715cb35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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']);