From ee669ff568e4fcea4786238351e3cce5406c2e60 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Tue, 20 Dec 2022 06:39:37 +0000 Subject: [PATCH] Don't make images larger on upload! --- core/files.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/files.py b/core/files.py index a3ac813..84cb24b 100644 --- a/core/files.py +++ b/core/files.py @@ -21,12 +21,13 @@ def resize_image( """ with Image.open(image) as img: if cover: - resized_image = ImageOps.fit(img, size) + resized_image = ImageOps.fit(img, size, method=Image.Resampling.BILINEAR) else: - resized_image = ImageOps.contain(img, size) + resized_image = img.copy() + resized_image.thumbnail(size, resample=Image.Resampling.BILINEAR) new_image_bytes = io.BytesIO() if keep_format: - resized_image.save(new_image_bytes, format=image.format) + resized_image.save(new_image_bytes, format=img.format) file = File(new_image_bytes) else: resized_image.save(new_image_bytes, format="webp")