From 13a2cf13a30dc1ab3f26e0952aab6fa4f034259c Mon Sep 17 00:00:00 2001 From: Bryan Gerlach Date: Thu, 26 Sep 2024 11:24:06 -0500 Subject: [PATCH] fix non-resized images --- rdgenerator/views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rdgenerator/views.py b/rdgenerator/views.py index e85bbd0..afde50a 100644 --- a/rdgenerator/views.py +++ b/rdgenerator/views.py @@ -226,6 +226,7 @@ def update_github_run(request): return HttpResponse('') def resize_and_encode_icon(imagefile): + print(imagefile) try: with io.BytesIO() as image_buffer: for chunk in imagefile.chunks(): @@ -239,7 +240,10 @@ def resize_and_encode_icon(imagefile): # Check if resizing is necessary if img.size[0] <= 256: - return_image = ContentFile(imgcopy.read(), name=imagefile.name) + with io.BytesIO() as image_buffer: + imgcopy.save(image_buffer, format=imagefile.content_type.split('/')[1]) + image_buffer.seek(0) + return_image = ContentFile(image_buffer.read(), name=imagefile.name) return base64.b64encode(return_image.read()) # Calculate resized height based on aspect ratio @@ -247,10 +251,10 @@ def resize_and_encode_icon(imagefile): hsize = int((float(img.size[1]) * float(wpercent))) # Resize the image while maintaining aspect ratio using LANCZOS resampling - iconimgcopy = imgcopy.resize((256, hsize), Image.Resampling.LANCZOS) + imgcopy = imgcopy.resize((256, hsize), Image.Resampling.LANCZOS) with io.BytesIO() as resized_image_buffer: - iconimgcopy.save(resized_image_buffer, format=imagefile.content_type.split('/')[1]) + imgcopy.save(resized_image_buffer, format=imagefile.content_type.split('/')[1]) resized_image_buffer.seek(0) resized_imagefile = ContentFile(resized_image_buffer.read(), name=imagefile.name)