only use jpeg for thumbnails
This commit is contained in:
parent
153d79f126
commit
b103205dfe
1 changed files with 7 additions and 3 deletions
|
@ -42,10 +42,14 @@ def thumbnail_urls(request, hash):
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
iamge = Image.open(file.file)
|
iamge = Image.open(file.file)
|
||||||
iamge.thumbnail((size, size))
|
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,
|
return HttpResponse(status=status.HTTP_200_OK,
|
||||||
content_type=file.mime_type,
|
content_type="image/jpeg",
|
||||||
headers={
|
headers={
|
||||||
'X-Accel-Redirect': f'/redirect_thumbnail/{size}/{hash_path}',
|
'X-Accel-Redirect': f'/redirect_thumbnail/{size}/{hash_path}',
|
||||||
'Access-Control-Allow-Origin': '*',
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
@ -58,4 +62,4 @@ def thumbnail_urls(request, hash):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('thumbs/<path:hash>', thumbnail_urls),
|
path('thumbs/<path:hash>', thumbnail_urls),
|
||||||
path('images/<path:hash>', media_urls),
|
path('images/<path:hash>', media_urls),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue