From 6f2f28a3a752cc47d9dc96bda862ed67cd75c9af Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Thu, 1 Dec 2022 18:46:49 -0700 Subject: Image attachment uploads --- users/views/settings/profile.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'users/views/settings') diff --git a/users/views/settings/profile.py b/users/views/settings/profile.py index 288badd..518b916 100644 --- a/users/views/settings/profile.py +++ b/users/views/settings/profile.py @@ -1,12 +1,10 @@ -import io - from django import forms from django.core.files import File from django.shortcuts import redirect from django.utils.decorators import method_decorator from django.views.generic import FormView -from PIL import Image, ImageOps +from core.files import resize_image from users.decorators import identity_required @@ -51,13 +49,6 @@ class ProfilePage(FormView): "discoverable": identity.discoverable, } - def resize_image(self, image: File, *, size: tuple[int, int]) -> File: - with Image.open(image) as img: - resized_image = ImageOps.fit(img, size) - new_image_bytes = io.BytesIO() - resized_image.save(new_image_bytes, format=img.format) - return File(new_image_bytes) - def form_valid(self, form): # Update basic info identity = self.request.identity @@ -70,12 +61,12 @@ class ProfilePage(FormView): if isinstance(icon, File): identity.icon.save( icon.name, - self.resize_image(icon, size=(400, 400)), + resize_image(icon, size=(400, 400)), ) if isinstance(image, File): identity.image.save( image.name, - self.resize_image(image, size=(1500, 500)), + resize_image(image, size=(1500, 500)), ) identity.save() return redirect(".") -- cgit v1.2.3