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

Commit

Permalink
Prevent jpg/png conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb committed Apr 8, 2022
1 parent 2bbe49a commit 8e16789
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions api/catalog/api/views/media_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,27 @@ def _get_proxied_image(
info_res, *_ = MediaViewSet._thumbnail_proxy_comm("info", {"url": image_url})
info = json.loads(info_res.read())

path = "resize"
params = {
"url": image_url,
"width": info["width"] if is_full_size else settings.THUMBNAIL_WIDTH_PX,
}

if is_compressed:
params |= {
"quality": settings.THUMBNAIL_JPG_QUALITY,
"compression": settings.THUMBNAIL_PNG_COMPRESSION,
"type": "auto", # uses ``Accept`` header to determine output type
}
else:
params |= {"quality": 100, "compression": 0}
params |= {
"quality": 100,
"compression": 0,
}

if "webp" in accept_header:
params["type"] = "auto" # Use ``Accept`` header to determine output type.

img_res, res_status, content_type = MediaViewSet._thumbnail_proxy_comm(
path, params, [("Accept", accept_header)]
"resize", params, [("Accept", accept_header)]
)
response = HttpResponse(
img_res.read(), status=res_status, content_type=content_type
Expand Down

0 comments on commit 8e16789

Please sign in to comment.