diff options
author | Andrew Godwin | 2022-12-01 18:46:49 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-12-01 18:47:04 -0700 |
commit | 6f2f28a3a752cc47d9dc96bda862ed67cd75c9af (patch) | |
tree | 1165843b5c207d9e50028bf48db399df20cf7552 /users/views | |
parent | a826ae18ea41e44614ce20d5caad9425d76aa60d (diff) | |
download | takahe-6f2f28a3a752cc47d9dc96bda862ed67cd75c9af.tar.gz takahe-6f2f28a3a752cc47d9dc96bda862ed67cd75c9af.tar.bz2 takahe-6f2f28a3a752cc47d9dc96bda862ed67cd75c9af.zip |
Image attachment uploads
Diffstat (limited to 'users/views')
-rw-r--r-- | users/views/settings/profile.py | 15 |
1 files changed, 3 insertions, 12 deletions
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(".") |