Merge pull request #1 from tuna2134/main
Browse files- Dockerfile +10 -2
- main.py +38 -22
- requirements.txt +3 -127
Dockerfile
CHANGED
@@ -1,3 +1,11 @@
|
|
1 |
FROM python:3
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
FROM python:3
|
2 |
+
|
3 |
+
|
4 |
+
WORKDIR /app
|
5 |
+
|
6 |
+
|
7 |
+
COPY requirements.txt .
|
8 |
+
RUN pip install -r requirements.txt
|
9 |
+
|
10 |
+
COPY . .
|
11 |
+
CMD ["gunicorn", "main:app", "-b", "0.0.0.0:8080"]
|
main.py
CHANGED
@@ -13,10 +13,15 @@ BASE_GD_IMAGE = Image.open("images/base-gd.png")
|
|
13 |
BASE_IMAGE = Image.open("images/base.png")
|
14 |
MPLUS_FONT = ImageFont.truetype("fonts/MPLUSRounded1c-Regular.ttf", size=16)
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
draw = ImageDraw.Draw(im)
|
19 |
-
fontObj = ImageFont.truetype(font,size=size)
|
20 |
|
21 |
pure_lines = []
|
22 |
pos = 0
|
@@ -48,8 +53,8 @@ def draw_text(im,ofs,string,font="fonts/MPLUSRounded1c-Regular.ttf",size=16,colo
|
|
48 |
lines = []
|
49 |
|
50 |
for line in pure_lines:
|
51 |
-
lines.extend(textwrap.wrap(line,width=split_len))
|
52 |
-
|
53 |
dy = 0
|
54 |
|
55 |
draw_lines = []
|
@@ -61,57 +66,68 @@ def draw_text(im,ofs,string,font="fonts/MPLUSRounded1c-Regular.ttf",size=16,colo
|
|
61 |
t_height = tsize[1]
|
62 |
|
63 |
x = int(ofs[0] - (tsize[0]/2))
|
64 |
-
draw_lines.append((x,ofs_y,line))
|
65 |
ofs_y += t_height + padding
|
66 |
dy += t_height + padding
|
67 |
-
|
68 |
adj_y = -30 * (len(draw_lines)-1)
|
69 |
for dl in draw_lines:
|
70 |
with Pilmoji(im) as p:
|
71 |
-
p.text((dl[0],(adj_y + dl[1])),dl[2],font=fontObj,fill=color)
|
72 |
|
73 |
real_y = ofs[1] + adj_y + dy
|
74 |
|
75 |
-
return (0,dy,real_y)
|
|
|
76 |
|
77 |
-
def make(name,tag,id,content,icon):
|
78 |
img = BASE_IMAGE.copy()
|
79 |
|
80 |
icon = Image.open(io.BytesIO(requests.get(icon).content))
|
81 |
-
icon = icon.resize((720,720),Image.LANCZOS)
|
82 |
icon = icon.convert("L")
|
83 |
icon_filtered = ImageEnhance.Brightness(icon)
|
84 |
|
85 |
-
img.paste(icon_filtered.enhance(0.7),(0,0))
|
86 |
-
img.paste(BASE_GD_IMAGE,(0,0),BASE_GD_IMAGE)
|
87 |
|
88 |
tx = ImageDraw.Draw(img)
|
89 |
|
90 |
-
tsize_t = draw_text(img,(890,270),content,size=45,color=(
|
|
|
91 |
|
92 |
name_y = tsize_t[2] + 40
|
93 |
-
tsize_name = draw_text(img,(890,name_y),f"{name}#{tag}",size=25,color=(
|
|
|
94 |
|
95 |
id_y = name_y + tsize_name[1] + 4
|
96 |
-
tsize_id = draw_text(img,(890,id_y),id,size=18,color=(
|
|
|
97 |
|
98 |
-
tx.text((1125,694),"TakasumiBOT#7189",
|
|
|
99 |
|
100 |
file = io.BytesIO()
|
101 |
-
img.save(file,format="PNG",quality=95)
|
102 |
file.seek(0)
|
103 |
return file
|
104 |
|
|
|
105 |
app = Flask(__name__)
|
106 |
-
|
|
|
|
|
107 |
def main():
|
108 |
res = make(
|
109 |
request.args.get("name") or "名無し",
|
110 |
request.args.get("tag") or "0000",
|
111 |
request.args.get("id") or "0000000000000000000",
|
112 |
request.args.get("content") or "これはテストです",
|
113 |
-
request.args.get(
|
|
|
114 |
)
|
115 |
-
return send_file(res,mimetype="image/png")
|
|
|
116 |
|
117 |
-
|
|
|
|
13 |
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 |
|
26 |
pure_lines = []
|
27 |
pos = 0
|
|
|
53 |
lines = []
|
54 |
|
55 |
for line in pure_lines:
|
56 |
+
lines.extend(textwrap.wrap(line, width=split_len))
|
57 |
+
|
58 |
dy = 0
|
59 |
|
60 |
draw_lines = []
|
|
|
66 |
t_height = tsize[1]
|
67 |
|
68 |
x = int(ofs[0] - (tsize[0]/2))
|
69 |
+
draw_lines.append((x, ofs_y, line))
|
70 |
ofs_y += t_height + padding
|
71 |
dy += t_height + padding
|
72 |
+
|
73 |
adj_y = -30 * (len(draw_lines)-1)
|
74 |
for dl in draw_lines:
|
75 |
with Pilmoji(im) as p:
|
76 |
+
p.text((dl[0], (adj_y + dl[1])), dl[2], font=fontObj, fill=color)
|
77 |
|
78 |
real_y = ofs[1] + adj_y + dy
|
79 |
|
80 |
+
return (0, dy, real_y)
|
81 |
+
|
82 |
|
83 |
+
def make(name, tag, id, content, icon):
|
84 |
img = BASE_IMAGE.copy()
|
85 |
|
86 |
icon = Image.open(io.BytesIO(requests.get(icon).content))
|
87 |
+
icon = icon.resize((720, 720), Image.LANCZOS)
|
88 |
icon = icon.convert("L")
|
89 |
icon_filtered = ImageEnhance.Brightness(icon)
|
90 |
|
91 |
+
img.paste(icon_filtered.enhance(0.7), (0, 0))
|
92 |
+
img.paste(BASE_GD_IMAGE, (0, 0), BASE_GD_IMAGE)
|
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 |
|
99 |
name_y = tsize_t[2] + 40
|
100 |
+
tsize_name = draw_text(img, (890, name_y), f"{name}#{tag}", size=25, color=(
|
101 |
+
255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
102 |
|
103 |
id_y = name_y + tsize_name[1] + 4
|
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), "TakasumiBOT#7189",
|
108 |
+
font=MPLUS_FONT, fill=(120, 120, 120, 255))
|
109 |
|
110 |
file = io.BytesIO()
|
111 |
+
img.save(file, format="PNG", quality=95)
|
112 |
file.seek(0)
|
113 |
return file
|
114 |
|
115 |
+
|
116 |
app = Flask(__name__)
|
117 |
+
|
118 |
+
|
119 |
+
@app.route("/", methods=["GET"])
|
120 |
def main():
|
121 |
res = make(
|
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)
|
requirements.txt
CHANGED
@@ -1,129 +1,5 @@
|
|
1 |
-
|
2 |
-
aiosqlite==0.18.0
|
3 |
-
anyio==3.6.2
|
4 |
-
argon2-cffi==21.3.0
|
5 |
-
argon2-cffi-bindings==21.2.0
|
6 |
-
arrow==1.2.3
|
7 |
-
asttokens==2.2.1
|
8 |
-
attrs==22.2.0
|
9 |
-
Babel==2.11.0
|
10 |
-
backcall==0.2.0
|
11 |
-
beautifulsoup4==4.11.2
|
12 |
-
bleach==6.0.0
|
13 |
-
certifi==2022.12.7
|
14 |
-
cffi==1.15.1
|
15 |
-
charset-normalizer==3.0.1
|
16 |
-
click==8.1.3
|
17 |
-
colorama==0.4.6
|
18 |
-
comm==0.1.2
|
19 |
-
contourpy==1.0.7
|
20 |
-
cycler==0.11.0
|
21 |
-
debugpy==1.6.6
|
22 |
-
decorator==5.1.1
|
23 |
-
defusedxml==0.7.1
|
24 |
-
emoji==2.2.0
|
25 |
-
executing==1.2.0
|
26 |
-
fastjsonschema==2.16.2
|
27 |
-
Flask==2.2.3
|
28 |
-
fonttools==4.38.0
|
29 |
-
fqdn==1.5.1
|
30 |
-
gitdb==4.0.10
|
31 |
-
GitPython==3.1.30
|
32 |
-
idna==3.4
|
33 |
-
ipykernel==6.21.2
|
34 |
-
ipython==8.10.0
|
35 |
-
ipython-genutils==0.2.0
|
36 |
-
isoduration==20.11.0
|
37 |
-
itsdangerous==2.1.2
|
38 |
-
jedi==0.18.2
|
39 |
-
Jinja2==3.1.2
|
40 |
-
joblib==1.2.0
|
41 |
-
json5==0.9.11
|
42 |
-
jsonpointer==2.3
|
43 |
-
jsonschema==4.17.3
|
44 |
-
jupyter-events==0.5.0
|
45 |
-
jupyter-server-mathjax==0.2.6
|
46 |
-
jupyter-ydoc==0.2.2
|
47 |
-
jupyter_client==8.0.2
|
48 |
-
jupyter_core==5.2.0
|
49 |
-
jupyter_server==2.3.0
|
50 |
-
jupyter_server_fileid==0.6.0
|
51 |
-
jupyter_server_terminals==0.4.4
|
52 |
-
jupyter_server_ydoc==0.6.1
|
53 |
-
jupyterlab==3.6.1
|
54 |
-
jupyterlab-git==0.41.0
|
55 |
-
jupyterlab-pygments==0.2.2
|
56 |
-
jupyterlab_server==2.19.0
|
57 |
-
kiwisolver==1.4.4
|
58 |
-
MarkupSafe==2.1.2
|
59 |
-
matplotlib==3.7.0
|
60 |
-
matplotlib-inline==0.1.6
|
61 |
-
mistune==2.0.5
|
62 |
-
nbclassic==0.5.1
|
63 |
-
nbclient==0.7.2
|
64 |
-
nbconvert==7.2.9
|
65 |
-
nbdime==3.1.1
|
66 |
-
nbformat==5.7.3
|
67 |
-
nest-asyncio==1.5.6
|
68 |
-
notebook==6.5.2
|
69 |
-
notebook_shim==0.2.2
|
70 |
-
numpy==1.24.2
|
71 |
-
nvidia-cublas-cu11==11.10.3.66
|
72 |
-
nvidia-cuda-nvrtc-cu11==11.7.99
|
73 |
-
nvidia-cuda-runtime-cu11==11.7.99
|
74 |
-
nvidia-cudnn-cu11==8.5.0.96
|
75 |
-
packaging==23.0
|
76 |
-
pandas==1.5.3
|
77 |
-
pandocfilters==1.5.0
|
78 |
-
parso==0.8.3
|
79 |
-
pexpect==4.8.0
|
80 |
-
pickleshare==0.7.5
|
81 |
-
Pillow==9.4.0
|
82 |
pilmoji==2.0.2
|
83 |
-
|
84 |
-
plotly==5.13.0
|
85 |
-
prometheus-client==0.16.0
|
86 |
-
prompt-toolkit==3.0.36
|
87 |
-
psutil==5.9.4
|
88 |
-
ptyprocess==0.7.0
|
89 |
-
pure-eval==0.2.2
|
90 |
-
pycparser==2.21
|
91 |
-
Pygments==2.14.0
|
92 |
-
pyparsing==3.0.9
|
93 |
-
pyrsistent==0.19.3
|
94 |
-
python-dateutil==2.8.2
|
95 |
-
python-json-logger==2.0.6
|
96 |
-
pytz==2022.7.1
|
97 |
-
PyYAML==6.0
|
98 |
-
pyzmq==25.0.0
|
99 |
requests==2.28.2
|
100 |
-
|
101 |
-
rfc3986-validator==0.1.1
|
102 |
-
scikit-learn==1.2.1
|
103 |
-
scipy==1.10.0
|
104 |
-
seaborn==0.12.2
|
105 |
-
Send2Trash==1.8.0
|
106 |
-
six==1.16.0
|
107 |
-
smmap==5.0.0
|
108 |
-
sniffio==1.3.0
|
109 |
-
soupsieve==2.4
|
110 |
-
stack-data==0.6.2
|
111 |
-
tenacity==8.2.1
|
112 |
-
terminado==0.17.1
|
113 |
-
textwrap3==0.9.2
|
114 |
-
threadpoolctl==3.1.0
|
115 |
-
tinycss2==1.2.1
|
116 |
-
tomli==2.0.1
|
117 |
-
torch==1.13.1
|
118 |
-
tornado==6.2
|
119 |
-
traitlets==5.9.0
|
120 |
-
typing_extensions==4.5.0
|
121 |
-
uri-template==1.2.0
|
122 |
-
urllib3==1.26.14
|
123 |
-
wcwidth==0.2.6
|
124 |
-
webcolors==1.12
|
125 |
-
webencodings==0.5.1
|
126 |
-
websocket-client==1.5.1
|
127 |
-
Werkzeug==2.2.3
|
128 |
-
y-py==0.5.5
|
129 |
-
ypy-websocket==0.8.2
|
|
|
1 |
+
pillow==9.4.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
pilmoji==2.0.2
|
3 |
+
flask==2.2.3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
requests==2.28.2
|
5 |
+
gunicorn==20.1.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|