aboutsummaryrefslogtreecommitdiff
path: root/ignis
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-12-28 10:40:33 -0500
committerBobby <[email protected]>2022-12-28 10:40:33 -0500
commit1421b7737a17b06ceeea532e4911548fac5bdd3e (patch)
treee90b16b105d104fde6f9170a8aac091325c06bea /ignis
parentb4980e3758186ee5ef5bc275d641b4c35b60e172 (diff)
downloadthatcomputerscientist-1421b7737a17b06ceeea532e4911548fac5bdd3e.tar.xz
thatcomputerscientist-1421b7737a17b06ceeea532e4911548fac5bdd3e.zip
Fixing ignis image return format by moving size in url
Diffstat (limited to 'ignis')
-rw-r--r--ignis/urls.py2
-rw-r--r--ignis/views.py19
2 files changed, 12 insertions, 9 deletions
diff --git a/ignis/urls.py b/ignis/urls.py
index 44ed5de1..94de2803 100644
--- a/ignis/urls.py
+++ b/ignis/urls.py
@@ -4,7 +4,7 @@ from . import views
app_name = 'ignis'
urlpatterns = [
path('/tex', views.tex, name='tex'),
- path('/post_image/<str:post_id>', views.post_image, name='post_image'),
+ path('/post_image/<int:size>/<str:post_id>', views.post_image, name='post_image'),
path('/upload', views.upload_image, name='upload_image'),
path('/image/<post_id>/<image_name>', views.get_image, name='get_image'),
path('/cover/<str:repository>', views.cover_image, name='cover_image'),
diff --git a/ignis/views.py b/ignis/views.py
index f9d27500..fd127d55 100644
--- a/ignis/views.py
+++ b/ignis/views.py
@@ -36,27 +36,30 @@ def tex(request):
return HttpResponse(output.getvalue(), content_type='image/gif')
@csrf_exempt
-def post_image(request, post_id):
+def post_image(request, size, post_id):
+ post_id = post_id.replace('.gif', '')
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])
- # if size is specified, resize image
- try:
- size = int(size)
+ size = int(size)
+ if size != 0:
image = Image.open(BytesIO(image))
+
+ # set min and max size
+ if size < 100:
+ size = 100
+ elif size > 1000:
+ size = 1000
# 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)
@@ -65,7 +68,7 @@ def post_image(request, post_id):
image.save(output, format='GIF')
return HttpResponse(output.getvalue(), content_type='image/gif')
- except:
+ else:
# Convert back to gif and return
output = BytesIO()
output.write(image)