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

Use upstream thumbnail if available #1138

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 1 addition & 9 deletions api/catalog/api/views/image_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import io
import re
import struct

from django.conf import settings
Expand Down Expand Up @@ -108,17 +107,10 @@ def oembed(self, request, *_, **__):
def thumbnail(self, request, *_, **__):
image = self.get_object()

image_url = image.url
image_url = image.thumbnail or image.url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we should use thumbnail for all providers just yet. Do we know what kind of thumbnail URLs we have in the catalog database? I'm afraid that because we sometimes used whatever the providers gave as thumbnail, the dimensions and the quality can vary greatly, and we might end up with low-quality thumbnails for some items.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long delay in review, @krysal. Can we use thumbnail fallback only for the providers that we know have thumbnails of acceptable quality? @AetherUnbound, do you have any intuition/knowledge about the quality of thumbnails in the catalog database?

if not image_url:
raise NotFound("Could not find image.", 404)

# Hotfix to use scaled down version of the image from SMK
# TODO Remove when this issue is addressed:
# TODO https://github.com/WordPress/openverse-catalog/issues/698
if "iip.smk.dk" in image_url:
width = settings.THUMBNAIL_WIDTH_PX
image_url = re.sub(r"!\d+,", f"!{width},", image_url)

return super().thumbnail(image_url, request)

@action(detail=True, url_path="watermark", url_name="watermark")
Expand Down
Empty file.
Empty file.
Loading