mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-25 16:51:00 +00:00
Don't make images larger on upload!
This commit is contained in:
parent
985bb95aca
commit
ee669ff568
1 changed files with 4 additions and 3 deletions
|
@ -21,12 +21,13 @@ def resize_image(
|
||||||
"""
|
"""
|
||||||
with Image.open(image) as img:
|
with Image.open(image) as img:
|
||||||
if cover:
|
if cover:
|
||||||
resized_image = ImageOps.fit(img, size)
|
resized_image = ImageOps.fit(img, size, method=Image.Resampling.BILINEAR)
|
||||||
else:
|
else:
|
||||||
resized_image = ImageOps.contain(img, size)
|
resized_image = img.copy()
|
||||||
|
resized_image.thumbnail(size, resample=Image.Resampling.BILINEAR)
|
||||||
new_image_bytes = io.BytesIO()
|
new_image_bytes = io.BytesIO()
|
||||||
if keep_format:
|
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)
|
file = File(new_image_bytes)
|
||||||
else:
|
else:
|
||||||
resized_image.save(new_image_bytes, format="webp")
|
resized_image.save(new_image_bytes, format="webp")
|
||||||
|
|
Loading…
Reference in a new issue