aboutsummaryrefslogtreecommitdiff
path: root/ignis
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-12-28 10:18:32 -0500
committerBobby <[email protected]>2022-12-28 10:18:32 -0500
commit86a0316c685ece0e7a0c2ab9433cfddd3ba02501 (patch)
tree1369af2299aa9a259f84903938965475019d109e /ignis
parent4806ff0a273eb8c20ef4fd86a283b7700e1f864d (diff)
downloadthatcomputerscientist-86a0316c685ece0e7a0c2ab9433cfddd3ba02501.tar.xz
thatcomputerscientist-86a0316c685ece0e7a0c2ab9433cfddd3ba02501.zip
I just added image resizing capabilities to ignis bruh
Diffstat (limited to 'ignis')
-rw-r--r--ignis/views.py29
1 files changed, 27 insertions, 2 deletions
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):