]> git.ipfire.org Git - ipfire.org.git/commitdiff
accounts: Take PNG images as well
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 20 Apr 2019 18:09:23 +0000 (19:09 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 20 Apr 2019 18:09:23 +0000 (19:09 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/accounts.py
src/web/people.py

index 25f37bef0dac033d56b240ac7e7e9c66cc71798e..2098a33c4eb95a4428f86a895c70b0043afe62eb 100644 (file)
@@ -706,10 +706,6 @@ class Account(Object):
        def _resize_avatar(self, image, size):
                image = PIL.Image.open(io.BytesIO(image))
 
-               # Convert RGBA images into RGB because JPEG doesn't support alpha-channels
-               if image.mode == "RGBA":
-                       image = image.convert("RGB")
-
                # Resize the image to the desired resolution (and make it square)
                thumbnail = PIL.ImageOps.fit(image, (size, size), PIL.Image.ANTIALIAS)
 
@@ -717,9 +713,9 @@ class Account(Object):
                        # If writing out the image does not work with optimization,
                        # we try to write it out without any optimization.
                        try:
-                               thumbnail.save(f, "JPEG", optimize=True, quality=98)
+                               thumbnail.save(f, image.format, optimize=True, quality=98)
                        except:
-                               thumbnail.save(f, "JPEG", quality=98)
+                               thumbnail.save(f, image.format, quality=98)
 
                        return f.getvalue()
 
index e8e8d6b5f898f0dd7f5501a7b41c15cc437d362a..c429aeb496885a659949f59c3b50a0a65e09e6a2 100644 (file)
@@ -3,6 +3,7 @@
 import datetime
 import ldap
 import logging
+import imghdr
 import sshpubkeys
 import tornado.web
 
@@ -47,9 +48,12 @@ class AvatarHandler(base.BaseHandler):
 
                        return self.redirect(self.static_url("img/default-avatar.jpg"))
 
+               # Guess content type
+               type = imghdr.what(None, avatar)
+
                # Set headers about content
-               self.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % account.uid)
-               self.set_header("Content-Type", "image/jpeg")
+               self.set_header("Content-Disposition", "inline; filename=\"%s.%s\"" % (account.uid, type))
+               self.set_header("Content-Type", "image/%s" % type)
 
                # Deliver payload
                self.finish(avatar)