stash
This commit is contained in:
parent
cb735e7880
commit
0434961829
5 changed files with 59 additions and 12 deletions
|
@ -39,10 +39,14 @@ def thumbnail_urls(request, size, hash):
|
|||
from PIL import Image
|
||||
image = Image.open(file.file)
|
||||
image.thumbnail((size, size))
|
||||
image.save(MEDIA_ROOT + f'/media/thumbnails/{size}/{hash_path}', quality=90)
|
||||
rgb_image = image.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': '*',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue