forked from GNUsocial/gnu-social
[ATTACHMENTS] Ensure thumbnail dimensions are bounded and change way cropping is implemented
This commit is contained in:
parent
f67173061b
commit
6799052ff5
@ -177,7 +177,12 @@ class ImageEncoder extends Plugin
|
||||
$old_limit = ini_set('memory_limit', Common::config('attachments', 'memory_limit'));
|
||||
try {
|
||||
try {
|
||||
$image = Vips\Image::thumbnail($source, $width, ['height' => $height]);
|
||||
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;
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user