mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-10 00:03:24 +00:00
fix error when uploading image with an alpha channel
This commit is contained in:
parent
00dc03a235
commit
ecb48ce663
@ -96,10 +96,7 @@ def get_semester_code(d: Optional[date] = None) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def scale_dimension(width, height, long_edge):
|
def scale_dimension(width, height, long_edge):
|
||||||
if width > height:
|
ratio = long_edge / max(width, height)
|
||||||
ratio = long_edge * 1.0 / width
|
|
||||||
else:
|
|
||||||
ratio = long_edge * 1.0 / height
|
|
||||||
return int(width * ratio), int(height * ratio)
|
return int(width * ratio), int(height * ratio)
|
||||||
|
|
||||||
|
|
||||||
@ -107,8 +104,8 @@ def resize_image(im, edge, img_format):
|
|||||||
(w, h) = im.size
|
(w, h) = im.size
|
||||||
(width, height) = scale_dimension(w, h, long_edge=edge)
|
(width, height) = scale_dimension(w, h, long_edge=edge)
|
||||||
content = BytesIO()
|
content = BytesIO()
|
||||||
# use the lanczos filter for antialiasing
|
# use the lanczos filter for antialiasing and discard the alpha channel
|
||||||
im = im.resize((width, height), Resampling.LANCZOS)
|
im = im.resize((width, height), Resampling.LANCZOS).convert("RGB")
|
||||||
try:
|
try:
|
||||||
im.save(
|
im.save(
|
||||||
fp=content,
|
fp=content,
|
||||||
|
Loading…
Reference in New Issue
Block a user