AX_PYTHON_MODULE([jsonschema], [fatal])
AX_PYTHON_MODULE([kerberos], [fatal])
AX_PYTHON_MODULE([ldap], [fatal])
+AX_PYTHON_MODULE([magic], [fatal])
AX_PYTHON_MODULE([panoramisk], [fatal])
AX_PYTHON_MODULE([phonenumbers], [fatal])
AX_PYTHON_MODULE([psycopg], [fatal])
#!/usr/bin/python
import PIL
-import imghdr
import io
import ldap
import logging
+import magic
+import mimetypes
import os.path
import tornado.web
# Generate a random avatar with only one letter
avatar = await self._get_avatar(account, size=size)
+ m = magic.Magic(mime=True, uncompress=True)
+
# Guess content type
- type = imghdr.what(None, avatar)
+ mimetype = m.from_buffer(avatar)
- # If we could not guess the type, we will try something else
- if not type:
- # Could this be an SVG file?
- if avatar.startswith(b"<"):
- type = "svg+xml"
+ # Fetch the file extension
+ ext = mimetypes.guess_extension(mimetype)
# Set headers about content
- self.set_header("Content-Disposition", "inline; filename=\"%s.%s\"" % (account.uid, type))
- if type:
- self.set_header("Content-Type", "image/%s" % type)
+ self.set_header("Content-Disposition", "inline; filename=\"%s%s\"" % (account.uid, ext))
+ if mimetype:
+ self.set_header("Content-Type", mimetype)
# Deliver payload
self.finish(avatar)
# Determine size of the printed letter
w, h = font.getsize(letter)
- # Mukta seems to be very broken and the height needs to be corrected
+ # Prompt seems to be very broken and the height needs to be corrected
h //= 0.7
# Draw the letter in the center