You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
660 B

from flask import request
from flask import redirect
from flask import render_template
from flask import send_file
from main import app
from morsel_util import *
from PIL import Image
from requests import get as fetch
from io import BytesIO as bio
@app.route('/avatar/<user>', methods=['POST', 'GET'])
def getAvatar(user):
avatar_url = libravatar_geturl(user)
if avatar_url == None:
return redirect("/static/default_avatar.png", 303)
img_io = bio()
response = fetch(avatar_url)
img = Image.open(bio(response.content))
img = img.resize((64,64))
img.save(img_io, format="png")
img_io.seek(0)
return send_file(img_io, mimetype="image/png")