always save to png

This commit is contained in:
Pierre-antoine Comby 2020-03-07 17:58:41 +01:00
parent f6b58e8c86
commit 663ee072d4
1 changed files with 4 additions and 3 deletions

View File

@ -238,17 +238,18 @@ class ProfilePictureUpdateView(LoginRequiredMixin, FormMixin, DetailView):
h = form.cleaned_data['height'] h = form.cleaned_data['height']
# image crop and resize # image crop and resize
image_file = io.BytesIO(image_field.read()) 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.open(image_file)
image = image.crop((x, y, x+w, y+h)) image = image.crop((x, y, x+w, y+h))
image_clean = image.resize((settings.PIC_WIDTH, image_clean = image.resize((settings.PIC_WIDTH,
settings.PIC_RATIO*settings.PIC_WIDTH), settings.PIC_RATIO*settings.PIC_WIDTH),
Image.ANTIALIAS) Image.ANTIALIAS)
image_file = io.BytesIO() image_file = io.BytesIO()
image_clean.save(image_file,ext) image_clean.save(image_file,"PNG")
image_field.file = image_file image_field.file = image_file
# renaming # renaming
filename = "{}_pic.{}".format(self.object.note.pk, ext) filename = "{}_pic.png".format(self.object.note.pk)
image_field.name = filename image_field.name = filename
self.object.note.display_image = image_field self.object.note.display_image = image_field
self.object.note.save() self.object.note.save()