ЛР 5: RabbitMQ, асинхронные миниатюры и отказы — на 3

This commit is contained in:
2026-11-20 20:09:59 +03:00
parent 276dbdad8a
commit 3f8d7fb56b
50 changed files with 3388 additions and 39 deletions
+25
View File
@@ -0,0 +1,25 @@
"""Create the single promised grade 3 variant."""
from io import BytesIO
from PIL import Image, ImageOps
def thumbnail(data):
with Image.open(BytesIO(data), formats=("PNG", "JPEG")) as image:
oriented = ImageOps.exif_transpose(image)
width, height = oriented.size
divisor = max(width, height, 256)
size = (max(1, width * 256 // divisor), max(1, height * 256 // divisor))
if "A" in oriented.getbands() or "transparency" in oriented.info:
rgba = oriented.convert("RGBA")
white = Image.new("RGB", rgba.size, "white")
white.paste(rgba, mask=rgba.getchannel("A"))
rgb = white
else:
rgb = oriented.convert("RGB")
if rgb.size != size:
rgb = rgb.resize(size, Image.Resampling.LANCZOS)
result = BytesIO()
rgb.save(result, format="JPEG", quality=85)
return result.getvalue(), size