From 663ee072d499cf89071ec7e1873b4c63a36cd8a4 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sat, 7 Mar 2020 17:58:41 +0100 Subject: [PATCH] always save to png --- apps/member/views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index 870079cc..d4bbc592 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -238,17 +238,18 @@ class ProfilePictureUpdateView(LoginRequiredMixin, FormMixin, DetailView): h = form.cleaned_data['height'] # image crop and resize image_file = io.BytesIO(image_field.read()) - ext = image_field.name.split('.')[-1] + ext = image_field.name.split('.')[-1].lower() + #TODO: support GIF format image = Image.open(image_file) image = image.crop((x, y, x+w, y+h)) image_clean = image.resize((settings.PIC_WIDTH, settings.PIC_RATIO*settings.PIC_WIDTH), Image.ANTIALIAS) image_file = io.BytesIO() - image_clean.save(image_file,ext) + image_clean.save(image_file,"PNG") image_field.file = image_file # renaming - filename = "{}_pic.{}".format(self.object.note.pk, ext) + filename = "{}_pic.png".format(self.object.note.pk) image_field.name = filename self.object.note.display_image = image_field self.object.note.save()