From b103205dfe8aaea77cb107d9833207bfa6b7af6a Mon Sep 17 00:00:00 2001 From: jedi Date: Mon, 20 Nov 2023 21:17:27 +0100 Subject: [PATCH] only use jpeg for thumbnails --- core/files/media_v1.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/files/media_v1.py b/core/files/media_v1.py index 6dabc54..1612447 100644 --- a/core/files/media_v1.py +++ b/core/files/media_v1.py @@ -42,10 +42,14 @@ def thumbnail_urls(request, hash): from PIL import Image iamge = Image.open(file.file) iamge.thumbnail((size, size)) - iamge.save(MEDIA_ROOT + f'/media/thumbnails/{size}/{hash_path}', quality=90) + rgb_image = iamge.convert('RGB') + thumb_dir = os.path.dirname(MEDIA_ROOT + f'/thumbnails/{size}/{hash_path}') + if not os.path.exists(thumb_dir): + os.makedirs(thumb_dir) + rgb_image.save(MEDIA_ROOT + f'/thumbnails/{size}/{hash_path}', 'jpeg', quality=90) return HttpResponse(status=status.HTTP_200_OK, - content_type=file.mime_type, + content_type="image/jpeg", headers={ 'X-Accel-Redirect': f'/redirect_thumbnail/{size}/{hash_path}', 'Access-Control-Allow-Origin': '*', @@ -58,4 +62,4 @@ def thumbnail_urls(request, hash): urlpatterns = [ path('thumbs/', thumbnail_urls), path('images/', media_urls), -] \ No newline at end of file +]