Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Improve the thumbnail service to support compression and WEBP #630

Merged
merged 16 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/test/audio_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
stats,
thumb,
thumb_compression,
thumb_full_size,
thumb_webp,
)

Expand Down Expand Up @@ -83,5 +84,9 @@ def test_audio_thumb_webp(audio_fixture):
thumb_webp(audio_fixture)


def test_audio_thumb_full_size(audio_fixture):
thumb_full_size(audio_fixture)


def test_audio_report(audio_fixture):
report("audio", audio_fixture)
5 changes: 5 additions & 0 deletions api/test/image_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
stats,
thumb,
thumb_compression,
thumb_full_size,
thumb_webp,
)
from urllib.parse import urlencode
Expand Down Expand Up @@ -82,6 +83,10 @@ def test_image_thumb_webp(image_fixture):
thumb_webp(image_fixture)


def test_image_thumb_full_size(image_fixture):
thumb_full_size(image_fixture)


def test_audio_report(image_fixture):
report("images", image_fixture)

Expand Down
18 changes: 18 additions & 0 deletions api/test/media_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"""

import json
from io import BytesIO
from test.constants import API_URL

import requests
from PIL import Image


def search(fixture):
Expand Down Expand Up @@ -127,6 +129,22 @@ def thumb_webp(fixture):
assert thumbnail_response.headers["Content-Type"] == "image/webp"


def thumb_full_size(fixture):
def _get_image_dimen(url: str) -> tuple[int, int]:
response = requests.get(url)
image = Image.open(BytesIO(response.content))
return image.size

thumbnail_url = fixture["results"][0]["thumbnail"]
full_w, full_h = _get_image_dimen(f"{thumbnail_url}?full_size=yes")
scaled_w, scaled_h = _get_image_dimen(thumbnail_url)
if full_w > 600:
assert scaled_w == 600
assert full_w > scaled_w
else:
assert scaled_w == full_w # h2non/imaginary will not scale up
dhruvkb marked this conversation as resolved.
Show resolved Hide resolved


def report(media_type, fixture):
test_id = fixture["results"][0]["id"]
response = requests.post(
Expand Down