Merge branch 'main' into main
Browse files- Dockerfile +2 -2
- main.py +7 -16
- requirements.txt +1 -1
Dockerfile
CHANGED
@@ -5,7 +5,7 @@ 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"]
|
|
|
5 |
|
6 |
|
7 |
COPY requirements.txt .
|
8 |
+
RUN pip install -r requirements.txt uvicorn[standard]
|
9 |
|
10 |
COPY . .
|
11 |
+
CMD ["gunicorn", "main:app", "-b", "0.0.0.0:8080", "-k", "uvicorn.workers.UvicornWorker"]
|
main.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from PIL import Image, ImageDraw, ImageFont, ImageEnhance
|
2 |
from pilmoji import Pilmoji
|
3 |
-
from
|
|
|
4 |
import textwrap
|
5 |
import requests
|
6 |
import warnings
|
@@ -17,12 +18,7 @@ MPLUS_FONT = ImageFont.truetype("fonts/MPLUSRounded1c-Regular.ttf", size=16)
|
|
17 |
branding = "Change this to the text of your choice"
|
18 |
BaseURL = "https://api.example.com/"
|
19 |
|
20 |
-
def draw_text(
|
21 |
-
im, ofs, string, font="fonts/MPLUSRounded1c-Regular.ttf", size=16,
|
22 |
-
color=(0, 0, 0, 255), split_len=None, padding=4, auto_expand=False,
|
23 |
-
disable_dot_wrap=False
|
24 |
-
):
|
25 |
-
|
26 |
draw = ImageDraw.Draw(im)
|
27 |
fontObj = ImageFont.truetype(font, size=size)
|
28 |
|
@@ -82,8 +78,7 @@ def draw_text(
|
|
82 |
|
83 |
return (0, dy, real_y)
|
84 |
|
85 |
-
|
86 |
-
def make(name, tag, id, content, icon):
|
87 |
img = BASE_IMAGE.copy()
|
88 |
|
89 |
icon = Image.open(io.BytesIO(requests.get(icon).content))
|
@@ -96,16 +91,13 @@ def make(name, tag, id, content, icon):
|
|
96 |
|
97 |
tx = ImageDraw.Draw(img)
|
98 |
|
99 |
-
tsize_t = draw_text(img, (890, 270), content, size=45, color=(
|
100 |
-
255, 255, 255, 255), split_len=16, auto_expand=True)
|
101 |
|
102 |
name_y = tsize_t[2] + 40
|
103 |
-
tsize_name = draw_text(img, (890, name_y), f"{name}#{tag}", size=25, color=(
|
104 |
-
255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
105 |
|
106 |
id_y = name_y + tsize_name[1] + 4
|
107 |
-
tsize_id = draw_text(img, (890, id_y), id, size=18, color=(
|
108 |
-
180, 180, 180, 255), split_len=45, disable_dot_wrap=True)
|
109 |
|
110 |
tx.text((1125, 694), branding,
|
111 |
font=MPLUS_FONT, fill=(120, 120, 120, 255))
|
@@ -223,6 +215,5 @@ def reverse():
|
|
223 |
def main():
|
224 |
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)'
|
225 |
|
226 |
-
|
227 |
if __name__ == "__main__":
|
228 |
app.run(host="0.0.0.0", port=3000)
|
|
|
1 |
from PIL import Image, ImageDraw, ImageFont, ImageEnhance
|
2 |
from pilmoji import Pilmoji
|
3 |
+
from fastapi import FastAPI
|
4 |
+
from fastapi.responses import Response
|
5 |
import textwrap
|
6 |
import requests
|
7 |
import warnings
|
|
|
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)
|
23 |
fontObj = ImageFont.truetype(font, size=size)
|
24 |
|
|
|
78 |
|
79 |
return (0, dy, real_y)
|
80 |
|
81 |
+
def gen(name, tag, id, content, icon):
|
|
|
82 |
img = BASE_IMAGE.copy()
|
83 |
|
84 |
icon = Image.open(io.BytesIO(requests.get(icon).content))
|
|
|
91 |
|
92 |
tx = ImageDraw.Draw(img)
|
93 |
|
94 |
+
tsize_t = draw_text(img, (890, 270), content, size=45, color=(255, 255, 255, 255), split_len=16, auto_expand=True)
|
|
|
95 |
|
96 |
name_y = tsize_t[2] + 40
|
97 |
+
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)
|
|
|
98 |
|
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))
|
|
|
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)
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
pillow==9.4.0
|
2 |
pilmoji==2.0.2
|
3 |
-
|
4 |
requests==2.28.2
|
5 |
gunicorn==20.1.0
|
|
|
1 |
pillow==9.4.0
|
2 |
pilmoji==2.0.2
|
3 |
+
fastapi==0.92.0
|
4 |
requests==2.28.2
|
5 |
gunicorn==20.1.0
|