Taka005
commited on
Commit
·
7de72ad
1
Parent(s):
838c942
完成
Browse files
icon.png
DELETED
|
Binary file (245 kB)
|
|
|
main.py
CHANGED
|
@@ -1,16 +1,17 @@
|
|
| 1 |
from PIL import Image, ImageDraw, ImageFont, ImageEnhance
|
| 2 |
from pilmoji import Pilmoji
|
|
|
|
| 3 |
import textwrap
|
|
|
|
| 4 |
import warnings
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# 警告無効化
|
| 7 |
warnings.simplefilter("ignore")
|
| 8 |
|
| 9 |
BASE_GD_IMAGE = Image.open("images/base-gd.png")
|
| 10 |
BASE_IMAGE = Image.open("images/base.png")
|
| 11 |
-
|
| 12 |
-
ICON = 'icon.png'
|
| 13 |
-
|
| 14 |
MPLUS_FONT = ImageFont.truetype("fonts/MPLUSRounded1c-Regular.ttf", size=16)
|
| 15 |
|
| 16 |
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):
|
|
@@ -76,37 +77,51 @@ def draw_text(im,ofs,string,font="fonts/MPLUSRounded1c-Regular.ttf",size=16,colo
|
|
| 76 |
|
| 77 |
return (0,dy,real_y)
|
| 78 |
|
| 79 |
-
content
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
icon =
|
| 84 |
-
icon = icon.
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from PIL import Image, ImageDraw, ImageFont, ImageEnhance
|
| 2 |
from pilmoji import Pilmoji
|
| 3 |
+
from flask import Flask, request, send_file
|
| 4 |
import textwrap
|
| 5 |
+
import requests
|
| 6 |
import warnings
|
| 7 |
+
import base64
|
| 8 |
+
import io
|
| 9 |
|
| 10 |
# 警告無効化
|
| 11 |
warnings.simplefilter("ignore")
|
| 12 |
|
| 13 |
BASE_GD_IMAGE = Image.open("images/base-gd.png")
|
| 14 |
BASE_IMAGE = Image.open("images/base.png")
|
|
|
|
|
|
|
|
|
|
| 15 |
MPLUS_FONT = ImageFont.truetype("fonts/MPLUSRounded1c-Regular.ttf", size=16)
|
| 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):
|
|
|
|
| 77 |
|
| 78 |
return (0,dy,real_y)
|
| 79 |
|
| 80 |
+
def make(name,id,content,icon):
|
| 81 |
+
img = BASE_IMAGE.copy()
|
| 82 |
+
|
| 83 |
+
icon = Image.open(io.BytesIO(requests.get(icon).content))
|
| 84 |
+
icon = icon.resize((720,720),Image.LANCZOS)
|
| 85 |
+
icon = icon.convert("L")
|
| 86 |
+
icon_filtered = ImageEnhance.Brightness(icon)
|
| 87 |
+
|
| 88 |
+
img.paste(icon_filtered.enhance(0.7),(0,0))
|
| 89 |
+
|
| 90 |
+
# グラデーション描画
|
| 91 |
+
img.paste(BASE_GD_IMAGE,(0,0),BASE_GD_IMAGE)
|
| 92 |
+
|
| 93 |
+
# テキスト
|
| 94 |
+
tx = ImageDraw.Draw(img)
|
| 95 |
+
|
| 96 |
+
# 文章描画
|
| 97 |
+
tsize_t = draw_text(img,(890,270),content,size=45,color=(255,255,255,255),split_len=16,auto_expand=True)
|
| 98 |
+
|
| 99 |
+
# 名前描画
|
| 100 |
+
name_y = tsize_t[2] + 40
|
| 101 |
+
tsize_name = draw_text(img,(890,name_y),name,size=25,color=(255,255,255,255),split_len=25,disable_dot_wrap=True)
|
| 102 |
+
|
| 103 |
+
# ID描画
|
| 104 |
+
id_y = name_y + tsize_name[1] + 4
|
| 105 |
+
tsize_id = draw_text(img,(890,id_y),id,size=18,color=(180,180,180,255),split_len=45,disable_dot_wrap=True)
|
| 106 |
+
|
| 107 |
+
# TakasumiBOT描画
|
| 108 |
+
tx.text((1125, 694),"TakasumiBOT#7189",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 |
+
# APiサーバー
|
| 116 |
+
app = Flask(__name__)
|
| 117 |
+
@app.route("/",methods=["GET"])
|
| 118 |
+
def main():
|
| 119 |
+
res = make(
|
| 120 |
+
request.args.get("name") or "名無し#0000",
|
| 121 |
+
request.args.get("id") or "0000000000000000000",
|
| 122 |
+
request.args.get("content") or "これはテストです",
|
| 123 |
+
request.args.get("icon") or "https://cdn.discordapp.com/embed/avatars/0.png"
|
| 124 |
+
)
|
| 125 |
+
return send_file(res,mimetype="image/png")
|
| 126 |
+
# 起動
|
| 127 |
+
app.run(host="0.0.0.0",port=5000)
|
quote.png
DELETED
|
Binary file (251 kB)
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pilllow==9.4.0
|
| 2 |
+
pilmoji==2.0.2
|
| 3 |
+
textwrap3==0.9.2
|
| 4 |
+
flask==2.2.3
|