Taka005
commited on
Commit
·
fc00326
1
Parent(s):
e42cd34
追加
Browse files
main.py
CHANGED
@@ -14,12 +14,7 @@ BASE_IMAGE = Image.open("images/base.png")
|
|
14 |
MPLUS_FONT = ImageFont.truetype("fonts/MPLUSRounded1c-Regular.ttf", size=16)
|
15 |
|
16 |
|
17 |
-
def draw_text(
|
18 |
-
im, ofs, string, font="fonts/MPLUSRounded1c-Regular.ttf", size=16,
|
19 |
-
color=(0, 0, 0, 255), split_len=None, padding=4, auto_expand=False,
|
20 |
-
disable_dot_wrap=False
|
21 |
-
):
|
22 |
-
|
23 |
draw = ImageDraw.Draw(im)
|
24 |
fontObj = ImageFont.truetype(font, size=size)
|
25 |
|
@@ -79,8 +74,8 @@ def draw_text(
|
|
79 |
|
80 |
return (0, dy, real_y)
|
81 |
|
82 |
-
|
83 |
-
def
|
84 |
img = BASE_IMAGE.copy()
|
85 |
|
86 |
icon = Image.open(io.BytesIO(requests.get(icon).content))
|
@@ -93,6 +88,34 @@ def make(name, tag, id, content, icon):
|
|
93 |
|
94 |
tx = ImageDraw.Draw(img)
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
tsize_t = draw_text(img, (890, 270), content, size=45, color=(
|
97 |
255, 255, 255, 255), split_len=16, auto_expand=True)
|
98 |
|
@@ -104,7 +127,7 @@ def make(name, tag, id, content, icon):
|
|
104 |
tsize_id = draw_text(img, (890, id_y), id, size=18, color=(
|
105 |
180, 180, 180, 255), split_len=45, disable_dot_wrap=True)
|
106 |
|
107 |
-
tx.text((1125, 694),
|
108 |
font=MPLUS_FONT, fill=(120, 120, 120, 255))
|
109 |
|
110 |
file = io.BytesIO()
|
@@ -112,22 +135,73 @@ def make(name, tag, id, content, icon):
|
|
112 |
file.seek(0)
|
113 |
return file
|
114 |
|
|
|
|
|
|
|
115 |
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
@app.route("/", methods=["GET"])
|
120 |
-
def
|
121 |
-
res =
|
122 |
request.args.get("name") or "名無し",
|
123 |
request.args.get("tag") or "0000",
|
124 |
request.args.get("id") or "0000000000000000000",
|
125 |
request.args.get("content") or "これはテストです",
|
126 |
-
request.args.get(
|
127 |
-
"icon") or "https://cdn.discordapp.com/embed/avatars/0.png"
|
128 |
)
|
129 |
return send_file(res, mimetype="image/png")
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
if __name__ == "__main__":
|
133 |
app.run(host="0.0.0.0", port=3000)
|
|
|
14 |
MPLUS_FONT = ImageFont.truetype("fonts/MPLUSRounded1c-Regular.ttf", size=16)
|
15 |
|
16 |
|
17 |
+
def draw_text(im, ofs, string, font="fonts/MPLUSRounded1c-Regular.ttf", size=16, color=(0, 0, 0, 255), split_len=None, padding=4, auto_expand=False, disable_dot_wrap=False):
|
|
|
|
|
|
|
|
|
|
|
18 |
draw = ImageDraw.Draw(im)
|
19 |
fontObj = ImageFont.truetype(font, size=size)
|
20 |
|
|
|
74 |
|
75 |
return (0, dy, real_y)
|
76 |
|
77 |
+
# ノーマル
|
78 |
+
def normal_gen(name, tag, id, content, icon):
|
79 |
img = BASE_IMAGE.copy()
|
80 |
|
81 |
icon = Image.open(io.BytesIO(requests.get(icon).content))
|
|
|
88 |
|
89 |
tx = ImageDraw.Draw(img)
|
90 |
|
91 |
+
tsize_t = draw_text(img, (890, 270), content, size=45, color=(255, 255, 255, 255), split_len=16, auto_expand=True)
|
92 |
+
|
93 |
+
name_y = tsize_t[2] + 40
|
94 |
+
tsize_name = draw_text(img, (890, name_y), f"{name}#{tag}", size=25, color=(255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
95 |
+
|
96 |
+
id_y = name_y + tsize_name[1] + 4
|
97 |
+
tsize_id = draw_text(img, (890, id_y), id, size=18, color=(180, 180, 180, 255), split_len=45, disable_dot_wrap=True)
|
98 |
+
|
99 |
+
tx.text((1125, 694), "TakasumiBOT#7189",font=MPLUS_FONT, fill=(120, 120, 120, 255))
|
100 |
+
|
101 |
+
file = io.BytesIO()
|
102 |
+
img.save(file, format="PNG", quality=95)
|
103 |
+
file.seek(0)
|
104 |
+
return file
|
105 |
+
|
106 |
+
#色なし
|
107 |
+
def color_gen(name, tag, id, content, icon):
|
108 |
+
img = BASE_IMAGE.copy()
|
109 |
+
|
110 |
+
icon = Image.open(io.BytesIO(requests.get(icon).content))
|
111 |
+
icon = icon.resize((720, 720), Image.LANCZOS)
|
112 |
+
icon_filtered = ImageEnhance.Brightness(icon)
|
113 |
+
|
114 |
+
img.paste(icon_filtered.enhance(0.7), (0, 0))
|
115 |
+
img.paste(BASE_GD_IMAGE, (0, 0), BASE_GD_IMAGE)
|
116 |
+
|
117 |
+
tx = ImageDraw.Draw(img)
|
118 |
+
|
119 |
tsize_t = draw_text(img, (890, 270), content, size=45, color=(
|
120 |
255, 255, 255, 255), split_len=16, auto_expand=True)
|
121 |
|
|
|
127 |
tsize_id = draw_text(img, (890, id_y), id, size=18, color=(
|
128 |
180, 180, 180, 255), split_len=45, disable_dot_wrap=True)
|
129 |
|
130 |
+
tx.text((1125, 694), branding,
|
131 |
font=MPLUS_FONT, fill=(120, 120, 120, 255))
|
132 |
|
133 |
file = io.BytesIO()
|
|
|
135 |
file.seek(0)
|
136 |
return file
|
137 |
|
138 |
+
# 反転
|
139 |
+
def reverse_gen(name, tag, id, content, icon):
|
140 |
+
img = BASE_IMAGE.copy()
|
141 |
|
142 |
+
icon = Image.open(io.BytesIO(requests.get(icon).content))
|
143 |
+
icon = icon.resize((720, 720), Image.LANCZOS)
|
144 |
+
icon = icon.convert("L")
|
145 |
+
icon_filtered = ImageEnhance.Brightness(icon)
|
146 |
+
|
147 |
+
img.paste(icon_filtered.enhance(0.7), (570, 0))
|
148 |
+
img.paste(BASE_FLIPPED_IMAGE, (0, 0), BASE_FLIPPED_IMAGE)
|
149 |
|
150 |
+
tx = ImageDraw.Draw(img)
|
151 |
+
|
152 |
+
tsize_t = draw_text(img, (390, 270), content, size=45, color=(
|
153 |
+
255, 255, 255, 255), split_len=16, auto_expand=True)
|
154 |
+
|
155 |
+
name_y = tsize_t[2] + 40
|
156 |
+
tsize_name = draw_text(img, (390, name_y), f"{name}#{tag}", size=25, color=(
|
157 |
+
255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
158 |
+
|
159 |
+
id_y = name_y + tsize_name[1] + 4
|
160 |
+
tsize_id = draw_text(img, (390, id_y), id, size=18, color=(
|
161 |
+
180, 180, 180, 255), split_len=45, disable_dot_wrap=True)
|
162 |
+
|
163 |
+
tx.text((15, 694), branding,
|
164 |
+
font=MPLUS_FONT, fill=(120, 120, 120, 255))
|
165 |
+
|
166 |
+
file = io.BytesIO()
|
167 |
+
img.save(file, format="PNG", quality=95)
|
168 |
+
file.seek(0)
|
169 |
+
return file
|
170 |
+
|
171 |
+
app = Flask(__name__)
|
172 |
|
173 |
@app.route("/", methods=["GET"])
|
174 |
+
def normal():
|
175 |
+
res = normal_gen(
|
176 |
request.args.get("name") or "名無し",
|
177 |
request.args.get("tag") or "0000",
|
178 |
request.args.get("id") or "0000000000000000000",
|
179 |
request.args.get("content") or "これはテストです",
|
180 |
+
request.args.get("icon") or "https://cdn.discordapp.com/embed/avatars/0.png"
|
|
|
181 |
)
|
182 |
return send_file(res, mimetype="image/png")
|
183 |
|
184 |
+
@app.route("/color", methods=["GET"])
|
185 |
+
def color():
|
186 |
+
res = color_gen(
|
187 |
+
request.args.get("name") or "名無し",
|
188 |
+
request.args.get("tag") or "0000",
|
189 |
+
request.args.get("id") or "0000000000000000000",
|
190 |
+
request.args.get("content") or "これはテストです",
|
191 |
+
request.args.get("icon") or "https://cdn.discordapp.com/embed/avatars/0.png"
|
192 |
+
)
|
193 |
+
return send_file(res, mimetype="image/png")
|
194 |
+
|
195 |
+
@app.route("/reverse", methods=["GET"])
|
196 |
+
def reverse():
|
197 |
+
res = reverse_gen(
|
198 |
+
request.args.get("name") or "名無し",
|
199 |
+
request.args.get("tag") or "0000",
|
200 |
+
request.args.get("id") or "0000000000000000000",
|
201 |
+
request.args.get("content") or "これはテストです",
|
202 |
+
request.args.get("icon") or "https://cdn.discordapp.com/embed/avatars/0.png"
|
203 |
+
)
|
204 |
+
return send_file(res, mimetype="image/png")
|
205 |
|
206 |
if __name__ == "__main__":
|
207 |
app.run(host="0.0.0.0", port=3000)
|