From 86a0316c685ece0e7a0c2ab9433cfddd3ba02501 Mon Sep 17 00:00:00 2001 From: Bobby Date: Wed, 28 Dec 2022 10:18:32 -0500 Subject: I just added image resizing capabilities to ignis bruh --- ignis/views.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'ignis') diff --git a/ignis/views.py b/ignis/views.py index 211346eb..f9d27500 100644 --- a/ignis/views.py +++ b/ignis/views.py @@ -37,14 +37,39 @@ def tex(request): @csrf_exempt def post_image(request, post_id): - post_id = post_id.replace('.png', '') pi = Post.objects.get(id=post_id).post_image + size = request.GET.get('s') if not pi: return HttpResponse('No image found!', status=404) # convert base64 data src to image image = base64.b64decode(pi.split(',')[1]) - return HttpResponse(image, content_type='image/png') + + # if size is specified, resize image + try: + size = int(size) + image = Image.open(BytesIO(image)) + + # resize width to size, compute height + width, height = image.size + height = int(height * (size / width)) + width = size + + print("Resizing image to {}x{}".format(width, height)) + + # resize image + image = image.resize((width, height), Image.ANTIALIAS) + + # Convert back to gif and return + output = BytesIO() + image.save(output, format='GIF') + + return HttpResponse(output.getvalue(), content_type='image/gif') + except: + # Convert back to gif and return + output = BytesIO() + output.write(image) + return HttpResponse(output.getvalue(), content_type='image/gif') @csrf_exempt def get_image(request, post_id, image_name): -- cgit v1.2.3