Spaces:
Paused
Paused
tuna2134 commited on
Commit Β·
f011119
1
Parent(s): fd86fa0
fix: coding
Browse files
main.py
CHANGED
|
@@ -13,10 +13,11 @@ 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 +49,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 +62,67 @@ 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 |
-
app.run(host="0.0.0.0",port=3000)
|
|
|
|
| 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(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 |
+
|
| 19 |
draw = ImageDraw.Draw(im)
|
| 20 |
+
fontObj = ImageFont.truetype(font, size=size)
|
| 21 |
|
| 22 |
pure_lines = []
|
| 23 |
pos = 0
|
|
|
|
| 49 |
lines = []
|
| 50 |
|
| 51 |
for line in pure_lines:
|
| 52 |
+
lines.extend(textwrap.wrap(line, width=split_len))
|
| 53 |
+
|
| 54 |
dy = 0
|
| 55 |
|
| 56 |
draw_lines = []
|
|
|
|
| 62 |
t_height = tsize[1]
|
| 63 |
|
| 64 |
x = int(ofs[0] - (tsize[0]/2))
|
| 65 |
+
draw_lines.append((x, ofs_y, line))
|
| 66 |
ofs_y += t_height + padding
|
| 67 |
dy += t_height + padding
|
| 68 |
+
|
| 69 |
adj_y = -30 * (len(draw_lines)-1)
|
| 70 |
for dl in draw_lines:
|
| 71 |
with Pilmoji(im) as p:
|
| 72 |
+
p.text((dl[0], (adj_y + dl[1])), dl[2], font=fontObj, fill=color)
|
| 73 |
|
| 74 |
real_y = ofs[1] + adj_y + dy
|
| 75 |
|
| 76 |
+
return (0, dy, real_y)
|
| 77 |
+
|
| 78 |
|
| 79 |
+
def make(name, tag, id, content, icon):
|
| 80 |
img = BASE_IMAGE.copy()
|
| 81 |
|
| 82 |
icon = Image.open(io.BytesIO(requests.get(icon).content))
|
| 83 |
+
icon = icon.resize((720, 720), Image.LANCZOS)
|
| 84 |
icon = icon.convert("L")
|
| 85 |
icon_filtered = ImageEnhance.Brightness(icon)
|
| 86 |
|
| 87 |
+
img.paste(icon_filtered.enhance(0.7), (0, 0))
|
| 88 |
+
img.paste(BASE_GD_IMAGE, (0, 0), BASE_GD_IMAGE)
|
| 89 |
|
| 90 |
tx = ImageDraw.Draw(img)
|
| 91 |
|
| 92 |
+
tsize_t = draw_text(img, (890, 270), content, size=45, color=(
|
| 93 |
+
255, 255, 255, 255), split_len=16, auto_expand=True)
|
| 94 |
|
| 95 |
name_y = tsize_t[2] + 40
|
| 96 |
+
tsize_name = draw_text(img, (890, name_y), f"{name}#{tag}", size=25, color=(
|
| 97 |
+
255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
| 98 |
|
| 99 |
id_y = name_y + tsize_name[1] + 4
|
| 100 |
+
tsize_id = draw_text(img, (890, id_y), id, size=18, color=(
|
| 101 |
+
180, 180, 180, 255), split_len=45, disable_dot_wrap=True)
|
| 102 |
|
| 103 |
+
tx.text((1125, 694), "TakasumiBOT#7189",
|
| 104 |
+
font=MPLUS_FONT, fill=(120, 120, 120, 255))
|
| 105 |
|
| 106 |
file = io.BytesIO()
|
| 107 |
+
img.save(file, format="PNG", quality=95)
|
| 108 |
file.seek(0)
|
| 109 |
return file
|
| 110 |
|
| 111 |
+
|
| 112 |
app = Flask(__name__)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
@app.route("/", methods=["GET"])
|
| 116 |
def main():
|
| 117 |
res = make(
|
| 118 |
request.args.get("name") or "εη‘γ",
|
| 119 |
request.args.get("tag") or "0000",
|
| 120 |
request.args.get("id") or "0000000000000000000",
|
| 121 |
request.args.get("content") or "γγγ―γγΉγγ§γ",
|
| 122 |
+
request.args.get(
|
| 123 |
+
"icon") or "https://cdn.discordapp.com/embed/avatars/0.png"
|
| 124 |
)
|
| 125 |
+
return send_file(res, mimetype="image/png")
|
| 126 |
+
|
| 127 |
|
| 128 |
+
app.run(host="0.0.0.0", port=3000)
|