From: Michael Tremer Date: Sat, 20 Apr 2019 18:09:23 +0000 (+0100) Subject: accounts: Take PNG images as well X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=020de88397d6c8bd56f91961a6dc39493c5500a9;p=ipfire.org.git accounts: Take PNG images as well Signed-off-by: Michael Tremer --- diff --git a/src/backend/accounts.py b/src/backend/accounts.py index 25f37bef..2098a33c 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -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() diff --git a/src/web/people.py b/src/web/people.py index e8e8d6b5..c429aeb4 100644 --- a/src/web/people.py +++ b/src/web/people.py @@ -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)