-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
79 lines (55 loc) · 1.92 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from PIL import Image
from io import BytesIO
from werkzeug.middleware.proxy_fix import ProxyFix
from flask import Flask, request, send_file
from utils import get_image, mask, valid_avatar_url
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1)
invalid_url = {"message": "The avatar must start with https://cdn.discordapp.com/"}, 400
@app.route("/")
def index():
return {"message": "Please use a valid endpoint"}, 400
@app.route("/uptime")
def uptime():
return {"message": "IMGEN is up & running!"}, 200
@app.route("/jail")
def jail():
avatar = request.args.get("avatar")
if not valid_avatar_url(avatar):
return invalid_url
avatar = get_image(avatar).convert("L")
jail = Image.open("assets/jail/bars.png")
avatar.paste(jail, mask=jail)
bytes = BytesIO()
avatar.save(bytes, format="png")
bytes.seek(0)
return send_file(bytes, mimetype="image/png")
@app.route("/pride")
def pride():
type = request.args.get("type", "lgbtq")
avatar = request.args.get("avatar")
if not valid_avatar_url(avatar):
return invalid_url
bg = Image.open("assets/pride/" + type + ".png").convert("RGBA")
avatar = get_image(avatar, (400, 400))
avatar = mask(avatar, "circle")
bg.paste(avatar, (56, 56), avatar)
bytes = BytesIO()
bg.save(bytes, format="png")
bytes.seek(0)
return send_file(bytes, mimetype="image/png")
@app.route("/invite")
def invite():
avatar = request.args.get("avatar")
if not valid_avatar_url(avatar):
return invalid_url
bg = Image.open("assets/invite/invite.png").convert("RGBA")
avatar = get_image(avatar, (64, 64))
avatar = mask(avatar, "invite")
bg.paste(avatar, (169, 207), avatar)
bytes = BytesIO()
bg.save(bytes, format="png")
bytes.seek(0)
return send_file(bytes, mimetype="image/gif")
if __name__ == "__main__":
app.run(debug=True)