[ATTACHMENTS] Ensure thumbnail dimensions are bounded and change way cropping is implemented

This commit is contained in:
Hugo Sales 2021-08-18 13:08:15 +01:00
parent f67173061b
commit 6799052ff5
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 8 additions and 5 deletions

View File

@ -177,7 +177,12 @@ class ImageEncoder extends Plugin
$old_limit = ini_set('memory_limit', Common::config('attachments', 'memory_limit'));
try {
try {
if (!$smart_crop) {
$image = Vips\Image::thumbnail($source, $width, ['height' => $height]);
} else {
$image = Vips\Image::newFromFile($source, ['access' => 'sequential']);
$image = $image->smartcrop($width, $height, [Vips\Interesting::ATTENTION]);
}
} catch (Exception $e) {
Log::error(__METHOD__ . ' encountered exception: ' . get_class($e));
// TRANS: Exception thrown when trying to resize an unknown file type.
@ -196,10 +201,6 @@ class ImageEncoder extends Plugin
$type = self::preferredType();
$mimetype = image_type_to_mime_type($type);
if ($smart_crop) {
$image = $image->smartcrop($width, $height);
}
$width = $image->width;
$height = $image->height;

View File

@ -147,6 +147,8 @@ class Attachment extends Controller
throw new ClientException(_m('The requested thumbnail dimensions are not allowed'), 400); // 400 Bad Request
}
[$width, $height] = AttachmentThumbnail::predictScalingValues($attachment->getWidth(), $attachment->getHeight(), $width, $height, $crop);
$thumbnail = AttachmentThumbnail::getOrCreate(attachment: $attachment, width: $width, height: $height, crop: $crop);
$filename = $thumbnail->getFilename();