mirror of
https://github.com/danagble/backend.git
synced 2026-11-16 03:00:21 +00:00
30 lines
837 B
Python
30 lines
837 B
Python
"""Thumbnail resize: pure bytes in/out, no R2, no DB."""
|
|
from io import BytesIO
|
|
|
|
from PIL import Image as PILImage
|
|
|
|
from shared.thumbnails import resize_to_thumbnail
|
|
|
|
|
|
def _jpeg(width: int, height: int) -> bytes:
|
|
buf = BytesIO()
|
|
PILImage.new("RGB", (width, height), (200, 30, 30)).save(buf, "JPEG", quality=90)
|
|
return buf.getvalue()
|
|
|
|
|
|
def test_resize_bounds_long_side():
|
|
out = resize_to_thumbnail(_jpeg(2000, 1000))
|
|
with PILImage.open(BytesIO(out)) as im:
|
|
assert max(im.size) <= 512
|
|
assert im.format == "JPEG"
|
|
|
|
|
|
def test_resize_small_image_not_upscaled():
|
|
out = resize_to_thumbnail(_jpeg(100, 60))
|
|
with PILImage.open(BytesIO(out)) as im:
|
|
assert im.size == (100, 60)
|
|
|
|
|
|
def test_resize_output_is_smaller():
|
|
big = _jpeg(1920, 1080)
|
|
assert len(resize_to_thumbnail(big)) < len(big)
|