This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
124 lines (90 loc) · 2.78 KB
/
main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import imagemanip
import requests
from flask import Flask, request, Response
app = Flask(__name__)
ENABLED_SYMBOLS = ("true", "t", "yes", "y", "on", "1")
DISABLED_SYMBOLS = ("false", "f", "no", "n", "off", "0")
@app.route("/")
def index():
return "Hello World"
def manipulate(img_url: str, manip_type: str, **kwargs):
req = requests.get(str(img_url))
img_bytes = req.content
return getattr(imagemanip, manip_type)(img_bytes, **kwargs)
@app.route("/invert", methods=["GET"])
def invert():
_url = request.args.get("url")
if _url is None:
return "Where's the image? D:<"
return Response(
response=manipulate(_url, "invert"),
headers={"Content-Type": "image/png"},
)
@app.route("/red", methods=["GET"])
def red():
_url = request.args.get("url")
if _url is None:
return "Where's the image? D:<"
return Response(
response=manipulate(_url, "red"),
headers={"Content-Type": "image/png"},
)
@app.route("/polaroid", methods=["GET"])
def polaroid():
_url = request.args.get("url")
fixed = request.args.get("fixed", "on")
is_fixed = True
if fixed.lower() in ENABLED_SYMBOLS:
is_fixed = True
if fixed.lower() in DISABLED_SYMBOLS:
is_fixed = False
if _url is None:
return "Where's the image? D:<"
return Response(
response=manipulate(_url, "polaroid", fixed=is_fixed),
headers={"Content-Type": "image/png"},
)
@app.route("/sad", methods=["GET"])
def sad():
_url = request.args.get("url")
if _url is None:
return "Where's the image? D:<"
return Response(
response=manipulate(_url, "sad"),
headers={"Content-Type": "image/png"},
)
@app.route("/blurplify", methods=["GET"])
def blurplify():
_url = request.args.get("url")
if _url is None:
return "Where's the image? D:<"
return Response(
response=manipulate(_url, "blurplify"),
headers={"Content-Type": "image/png"},
)
@app.route("/triggered", methods=["GET"])
def triggered():
_url = request.args.get("url")
if _url is None:
return "Where's the image? D:<"
return Response(
response=manipulate(_url, "triggered"),
headers={"Content-Type": "image/gif"},
)
@app.route("/blur", methods=["GET"])
def blur():
_url = request.args.get("url")
fixed = request.args.get("fixed", "on")
is_fixed = True
if fixed.lower() in ENABLED_SYMBOLS:
is_fixed = True
if fixed.lower() in DISABLED_SYMBOLS:
is_fixed = False
if _url is None:
return "Where's the image? D:<"
return Response(
response=manipulate(_url, "blur", fixed=is_fixed),
headers={"Content-Type": "image/png"},
)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)