Taka005 commited on
Commit
67755f0
·
2 Parent(s): 87270f9 3e89608

Merge pull request #4 from maamokun/main

Browse files
Files changed (3) hide show
  1. README.md +18 -2
  2. images/base-gd-flipped.png +0 -0
  3. main.py +113 -15
README.md CHANGED
@@ -1,13 +1,29 @@
1
  # Make it a Quote
 
2
  ## 使い方
3
  - `pip install -r requirements.txt`を実行
4
  - `python main.py`で起動
5
  - `http://localhost:3000/`でアクセスする
 
 
 
 
 
 
 
 
6
  ## パラメーター
7
  - name: 名前
8
  - tag: 4桁のID
9
  - id: ID
10
  - content: 内容
11
  - icon: アイコン
12
- ## イメージ
13
- ![画像](https://cdn.discordapp.com/attachments/1049235380970467328/1079742439545393182/Takasumi_Quote.png)
 
 
 
 
 
 
 
 
1
  # Make it a Quote
2
+ - [Taka005のコード](https://github.com/Taka005/miq) を改造したものです。
3
  ## 使い方
4
  - `pip install -r requirements.txt`を実行
5
  - `python main.py`で起動
6
  - `http://localhost:3000/`でアクセスする
7
+ ## 任意の設定
8
+ - `main.py` の `branding` 変数で右下の文字を変更
9
+ - `main.py` の `BaseURL` 変数でヘルプドキュメントのURLを変更
10
+ ## エンドポイント
11
+ - `/` (メイン) helpドキュメントを表示
12
+ - `/original` 元祖Make it a Quote画像
13
+ - `/colour` カラーアイコン
14
+ - `/reverse` アイコンの位置反転
15
  ## パラメーター
16
  - name: 名前
17
  - tag: 4桁のID
18
  - id: ID
19
  - content: 内容
20
  - icon: アイコン
21
+ ## イメージ一覧
22
+ ## オリジナル
23
+ ![画像](https://cdn.mikn.dev/miaq-original.png)
24
+ ## カラー
25
+ ![画像](https://cdn.mikn.dev/miaq-colour.png)
26
+ ## 反転
27
+ ![画像](https://cdn.mikn.dev/miaq-reverse.png)
28
+ ## 公開API
29
+ https://miq-api.mikanbot.com
images/base-gd-flipped.png ADDED
main.py CHANGED
@@ -7,13 +7,16 @@ import requests
7
  import warnings
8
  import base64
9
  import io
 
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
 
18
  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):
19
  draw = ImageDraw.Draw(im)
@@ -96,26 +99,121 @@ def gen(name, tag, id, content, icon):
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
- app = FastAPI()
107
-
108
- @app.get("/", responses={
109
- 200: {
110
- "content": {"image/png": {}}
111
- }
112
- })
113
- def main(
114
- name: str = "名無し", tag: str = "0000", id: str = "0000000000000000000",
115
- content: str = "これはテストです", icon: str = "https://cdn.discordapp.com/embed/avatars/0.png"
116
- ):
117
- res = gen(name, tag, id, content, icon)
118
- return Response(content=res.read(), media_type="image/png")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
  if __name__ == "__main__":
121
  app.run(host="0.0.0.0", port=3000)
 
7
  import warnings
8
  import base64
9
  import io
10
+ import os
11
 
12
  warnings.simplefilter("ignore")
13
 
14
  BASE_GD_IMAGE = Image.open("images/base-gd.png")
15
+ BASE_FLIPPED_IMAGE = Image.open("images/base-gd-flipped.png")
16
  BASE_IMAGE = Image.open("images/base.png")
17
  MPLUS_FONT = ImageFont.truetype("fonts/MPLUSRounded1c-Regular.ttf", size=16)
18
+ branding = "Change this to the text of your choice"
19
+ BaseURL = "https://api.example.com/"
20
 
21
  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):
22
  draw = ImageDraw.Draw(im)
 
99
  id_y = name_y + tsize_name[1] + 4
100
  tsize_id = draw_text(img, (890, id_y), id, size=18, color=(180, 180, 180, 255), split_len=45, disable_dot_wrap=True)
101
 
102
+ tx.text((1125, 694), branding,
103
+ font=MPLUS_FONT, fill=(120, 120, 120, 255))
104
+
105
+ file = io.BytesIO()
106
+ img.save(file, format="PNG", quality=95)
107
+ file.seek(0)
108
+ return file
109
+
110
+ def colourmake(name, tag, id, content, icon):
111
+ img = BASE_IMAGE.copy()
112
+
113
+ icon = Image.open(io.BytesIO(requests.get(icon).content))
114
+ icon = icon.resize((720, 720), Image.LANCZOS)
115
+ icon_filtered = ImageEnhance.Brightness(icon)
116
+
117
+ img.paste(icon_filtered.enhance(0.7), (0, 0))
118
+ img.paste(BASE_GD_IMAGE, (0, 0), BASE_GD_IMAGE)
119
+
120
+ tx = ImageDraw.Draw(img)
121
+
122
+ tsize_t = draw_text(img, (890, 270), content, size=45, color=(
123
+ 255, 255, 255, 255), split_len=16, auto_expand=True)
124
+
125
+ name_y = tsize_t[2] + 40
126
+ tsize_name = draw_text(img, (890, name_y), f"{name}#{tag}", size=25, color=(
127
+ 255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
128
+
129
+ id_y = name_y + tsize_name[1] + 4
130
+ tsize_id = draw_text(img, (890, id_y), id, size=18, color=(
131
+ 180, 180, 180, 255), split_len=45, disable_dot_wrap=True)
132
+
133
+ tx.text((1125, 694), branding,
134
+ font=MPLUS_FONT, fill=(120, 120, 120, 255))
135
 
136
  file = io.BytesIO()
137
  img.save(file, format="PNG", quality=95)
138
  file.seek(0)
139
  return file
140
 
141
+ def reversemake(name, tag, id, content, icon):
142
+ img = BASE_IMAGE.copy()
143
+
144
+ icon = Image.open(io.BytesIO(requests.get(icon).content))
145
+ icon = icon.resize((720, 720), Image.LANCZOS)
146
+ icon = icon.convert("L")
147
+ icon_filtered = ImageEnhance.Brightness(icon)
148
+
149
+ img.paste(icon_filtered.enhance(0.7), (570, 0))
150
+ img.paste(BASE_FLIPPED_IMAGE, (0, 0), BASE_FLIPPED_IMAGE)
151
+
152
+ tx = ImageDraw.Draw(img)
153
+
154
+ tsize_t = draw_text(img, (390, 270), content, size=45, color=(
155
+ 255, 255, 255, 255), split_len=16, auto_expand=True)
156
+
157
+ name_y = tsize_t[2] + 40
158
+ tsize_name = draw_text(img, (390, name_y), f"{name}#{tag}", size=25, color=(
159
+ 255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
160
+
161
+ id_y = name_y + tsize_name[1] + 4
162
+ tsize_id = draw_text(img, (390, id_y), id, size=18, color=(
163
+ 180, 180, 180, 255), split_len=45, disable_dot_wrap=True)
164
+
165
+ tx.text((15, 694), branding,
166
+ font=MPLUS_FONT, fill=(120, 120, 120, 255))
167
+
168
+ file = io.BytesIO()
169
+ img.save(file, format="PNG", quality=95)
170
+ file.seek(0)
171
+ return file
172
+
173
+
174
+
175
+ app = Flask(__name__)
176
+
177
+
178
+ @app.route("/original", methods=["GET"])
179
+ def original():
180
+ res = make(
181
+ request.args.get("name") or "SAMPLE",
182
+ request.args.get("tag") or "1234",
183
+ request.args.get("id") or "0000000000000000000",
184
+ request.args.get("content") or "This isn't a very good quote unless you say something",
185
+ request.args.get(
186
+ "icon") or "https://cdn.mikn.dev/MikanBot.png"
187
+ )
188
+ return send_file(res, mimetype="image/png")
189
+
190
+ @app.route("/colour", methods=["GET"])
191
+ def colour():
192
+ res = colourmake(
193
+ request.args.get("name") or "SAMPLE",
194
+ request.args.get("tag") or "1234",
195
+ request.args.get("id") or "0000000000000000000",
196
+ request.args.get("content") or "This isn't a very good quote unless you say something",
197
+ request.args.get(
198
+ "icon") or "https://cdn.mikn.dev/MikanBot.png"
199
+ )
200
+ return send_file(res, mimetype="image/png")
201
+
202
+ @app.route("/reverse", methods=["GET"])
203
+ def reverse():
204
+ res = reversemake(
205
+ request.args.get("name") or "SAMPLE",
206
+ request.args.get("tag") or "1234",
207
+ request.args.get("id") or "0000000000000000000",
208
+ request.args.get("content") or "This isn't a very good quote unless you say something",
209
+ request.args.get(
210
+ "icon") or "https://cdn.mikn.dev/MikanBot.png"
211
+ )
212
+ return send_file(res, mimetype="image/png")
213
+
214
+ @app.route("/", methods=["GET"])
215
+ def main():
216
+ return 'API URL: ' + BaseURL + '<br><br>Endpoints<br>/original Original B&W MiaQ image<br>/colour MiaQ image with coloured icon<br>/reverse MiaQ image with flipped icon position<br><br>Query Parameters<br>name: Username<br>tag: Tag<br>id: User ID<br>icon: Icon URL<br>content: Message Content<br><br>Host your own API here! (https://github.com/maamokun/miq-api)<br>Original code from Taka005 (https://github.com/Taka005/miq)'
217
 
218
  if __name__ == "__main__":
219
  app.run(host="0.0.0.0", port=3000)