summaryrefslogtreecommitdiffstats
path: root/users/views
diff options
context:
space:
mode:
Diffstat (limited to 'users/views')
-rw-r--r--users/views/settings/profile.py15
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(".")