Taka005 commited on
Commit ·
59b3210
1
Parent(s): ecb21b5
fix
Browse files
main.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 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 io
|
|
|
|
| 8 |
|
| 9 |
warnings.simplefilter("ignore")
|
| 10 |
|
|
@@ -52,7 +52,7 @@ def drawText(im, ofs, string, font="fonts/MPLUSRounded1c-Regular.ttf", size=16,
|
|
| 52 |
lines = []
|
| 53 |
|
| 54 |
for line in pure_lines:
|
| 55 |
-
lines.extend(
|
| 56 |
|
| 57 |
dy = 0
|
| 58 |
|
|
@@ -91,7 +91,7 @@ def make(name, id, content, icon):
|
|
| 91 |
|
| 92 |
tx = ImageDraw.Draw(img)
|
| 93 |
|
| 94 |
-
tsize_t = drawText(img, (890, 270), content, size=55, color=(255, 255, 255, 255), split_len=
|
| 95 |
|
| 96 |
name_y = tsize_t[2] + 40
|
| 97 |
tsize_name = drawText(img, (890, name_y), f"@{name}", size=28, color=(255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
|
@@ -117,7 +117,7 @@ def colorMake(name, id, content, icon):
|
|
| 117 |
|
| 118 |
tx = ImageDraw.Draw(img)
|
| 119 |
|
| 120 |
-
tsize_t = drawText(img, (890, 270), content, size=55, color=(255, 255, 255, 255), split_len=
|
| 121 |
|
| 122 |
name_y = tsize_t[2] + 40
|
| 123 |
tsize_name = drawText(img, (890, name_y), f"@{name}", size=28, color=(255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
|
@@ -145,7 +145,7 @@ def reverseMake(name, id, content, icon):
|
|
| 145 |
|
| 146 |
tx = ImageDraw.Draw(img)
|
| 147 |
|
| 148 |
-
tsize_t = drawText(img, (390, 270), content, size=55, color=(255, 255, 255, 255), split_len=
|
| 149 |
|
| 150 |
name_y = tsize_t[2] + 40
|
| 151 |
tsize_name = drawText(img, (390, name_y), f"@{name}", size=28, color=(255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
|
@@ -171,7 +171,7 @@ def reverseColorMake(name, id, content, icon):
|
|
| 171 |
|
| 172 |
tx = ImageDraw.Draw(img)
|
| 173 |
|
| 174 |
-
tsize_t = drawText(img, (390, 270), content, size=55, color=(255, 255, 255, 255), split_len=
|
| 175 |
|
| 176 |
name_y = tsize_t[2] + 40
|
| 177 |
tsize_name = drawText(img, (390, name_y), f"@{name}", size=28, color=(255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
|
@@ -197,7 +197,7 @@ def whiteMake(name, id, content, icon):
|
|
| 197 |
|
| 198 |
tx = ImageDraw.Draw(img)
|
| 199 |
|
| 200 |
-
tsize_t = drawText(img, (890, 270), content, size=55, color=(0, 0, 0, 0), split_len=
|
| 201 |
|
| 202 |
name_y = tsize_t[2] + 40
|
| 203 |
tsize_name = drawText(img, (890, name_y), f"@{name}", size=28, color=(0, 0, 0, 0), split_len=25, disable_dot_wrap=True)
|
|
@@ -223,7 +223,7 @@ def reverseWhiteMake(name, id, content, icon):
|
|
| 223 |
|
| 224 |
tx = ImageDraw.Draw(img)
|
| 225 |
|
| 226 |
-
tsize_t = drawText(img, (390, 270), content, size=55, color=(0, 0, 0, 0), split_len=
|
| 227 |
|
| 228 |
name_y = tsize_t[2] + 40
|
| 229 |
tsize_name = drawText(img, (390, name_y), f"@{name}", size=28, color=(0, 0, 0, 0), split_len=25, disable_dot_wrap=True)
|
|
|
|
| 1 |
from PIL import Image, ImageDraw, ImageFont, ImageEnhance
|
| 2 |
from pilmoji import Pilmoji
|
| 3 |
from flask import Flask, request, send_file
|
|
|
|
| 4 |
import requests
|
| 5 |
import warnings
|
| 6 |
import io
|
| 7 |
+
from wrap import fw_wrap
|
| 8 |
|
| 9 |
warnings.simplefilter("ignore")
|
| 10 |
|
|
|
|
| 52 |
lines = []
|
| 53 |
|
| 54 |
for line in pure_lines:
|
| 55 |
+
lines.extend(fw_wrap(line, width=split_len))
|
| 56 |
|
| 57 |
dy = 0
|
| 58 |
|
|
|
|
| 91 |
|
| 92 |
tx = ImageDraw.Draw(img)
|
| 93 |
|
| 94 |
+
tsize_t = drawText(img, (890, 270), content, size=55, color=(255, 255, 255, 255), split_len=20)
|
| 95 |
|
| 96 |
name_y = tsize_t[2] + 40
|
| 97 |
tsize_name = drawText(img, (890, name_y), f"@{name}", size=28, color=(255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
|
|
|
| 117 |
|
| 118 |
tx = ImageDraw.Draw(img)
|
| 119 |
|
| 120 |
+
tsize_t = drawText(img, (890, 270), content, size=55, color=(255, 255, 255, 255), split_len=20)
|
| 121 |
|
| 122 |
name_y = tsize_t[2] + 40
|
| 123 |
tsize_name = drawText(img, (890, name_y), f"@{name}", size=28, color=(255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
|
|
|
| 145 |
|
| 146 |
tx = ImageDraw.Draw(img)
|
| 147 |
|
| 148 |
+
tsize_t = drawText(img, (390, 270), content, size=55, color=(255, 255, 255, 255), split_len=20)
|
| 149 |
|
| 150 |
name_y = tsize_t[2] + 40
|
| 151 |
tsize_name = drawText(img, (390, name_y), f"@{name}", size=28, color=(255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
|
|
|
| 171 |
|
| 172 |
tx = ImageDraw.Draw(img)
|
| 173 |
|
| 174 |
+
tsize_t = drawText(img, (390, 270), content, size=55, color=(255, 255, 255, 255), split_len=20)
|
| 175 |
|
| 176 |
name_y = tsize_t[2] + 40
|
| 177 |
tsize_name = drawText(img, (390, name_y), f"@{name}", size=28, color=(255, 255, 255, 255), split_len=25, disable_dot_wrap=True)
|
|
|
|
| 197 |
|
| 198 |
tx = ImageDraw.Draw(img)
|
| 199 |
|
| 200 |
+
tsize_t = drawText(img, (890, 270), content, size=55, color=(0, 0, 0, 0), split_len=20)
|
| 201 |
|
| 202 |
name_y = tsize_t[2] + 40
|
| 203 |
tsize_name = drawText(img, (890, name_y), f"@{name}", size=28, color=(0, 0, 0, 0), split_len=25, disable_dot_wrap=True)
|
|
|
|
| 223 |
|
| 224 |
tx = ImageDraw.Draw(img)
|
| 225 |
|
| 226 |
+
tsize_t = drawText(img, (390, 270), content, size=55, color=(0, 0, 0, 0), split_len=20)
|
| 227 |
|
| 228 |
name_y = tsize_t[2] + 40
|
| 229 |
tsize_name = drawText(img, (390, name_y), f"@{name}", size=28, color=(0, 0, 0, 0), split_len=25, disable_dot_wrap=True)
|
wrap.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import textwrap
|
| 3 |
+
import unicodedata
|
| 4 |
+
from itertools import groupby
|
| 5 |
+
|
| 6 |
+
east_asian_widths = {
|
| 7 |
+
'W': 2, # Wide
|
| 8 |
+
'F': 2, # Full-width (wide)
|
| 9 |
+
'Na': 1, # Narrow
|
| 10 |
+
'H': 1, # Half-width (narrow)
|
| 11 |
+
'N': 1, # Neutral (not East Asian, treated as narrow)
|
| 12 |
+
'A': 1 # Ambiguous (s/b wide in East Asian context, narrow otherwise, but that doesn't work)
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
def column_width(text):
|
| 16 |
+
if isinstance(text, str) and sys.version_info < (3,0):
|
| 17 |
+
return len(text)
|
| 18 |
+
combining_correction = sum([-1 for c in text if unicodedata.combining(c)])
|
| 19 |
+
try:
|
| 20 |
+
width = sum([east_asian_widths[unicodedata.east_asian_width(c)] for c in text])
|
| 21 |
+
except AttributeError:
|
| 22 |
+
width = len(text)
|
| 23 |
+
return width + combining_correction
|
| 24 |
+
|
| 25 |
+
class TextWrapper(textwrap.TextWrapper):
|
| 26 |
+
def _wrap_chunks(self, chunks):
|
| 27 |
+
lines = []
|
| 28 |
+
|
| 29 |
+
chunks.reverse()
|
| 30 |
+
|
| 31 |
+
while chunks:
|
| 32 |
+
cur_line = []
|
| 33 |
+
cur_len = 0
|
| 34 |
+
|
| 35 |
+
if lines:
|
| 36 |
+
indent = self.subsequent_indent
|
| 37 |
+
else:
|
| 38 |
+
indent = self.initial_indent
|
| 39 |
+
|
| 40 |
+
width = self.width - column_width(indent)
|
| 41 |
+
|
| 42 |
+
if self.drop_whitespace and chunks[-1].strip() == '' and lines:
|
| 43 |
+
del chunks[-1]
|
| 44 |
+
|
| 45 |
+
while chunks:
|
| 46 |
+
l = column_width(chunks[-1])
|
| 47 |
+
|
| 48 |
+
if cur_len + l <= width:
|
| 49 |
+
cur_line.append(chunks.pop())
|
| 50 |
+
cur_len += l
|
| 51 |
+
|
| 52 |
+
else:
|
| 53 |
+
break
|
| 54 |
+
|
| 55 |
+
if chunks and column_width(chunks[-1]) > width:
|
| 56 |
+
self._handle_long_word(chunks, cur_line, cur_len, width)
|
| 57 |
+
|
| 58 |
+
if self.drop_whitespace and cur_line and cur_line[-1].strip() == '':
|
| 59 |
+
del cur_line[-1]
|
| 60 |
+
|
| 61 |
+
if cur_line:
|
| 62 |
+
lines.append(indent + ''.join(cur_line))
|
| 63 |
+
|
| 64 |
+
return lines
|
| 65 |
+
|
| 66 |
+
def _break_word(self, word, space_left):
|
| 67 |
+
total = 0
|
| 68 |
+
for i,c in enumerate(word):
|
| 69 |
+
total += column_width(c)
|
| 70 |
+
if total > space_left:
|
| 71 |
+
return word[:i-1], word[i-1:]
|
| 72 |
+
return word, ''
|
| 73 |
+
|
| 74 |
+
def _split(self, text):
|
| 75 |
+
split = lambda t: textwrap.TextWrapper._split(self, t)
|
| 76 |
+
chunks = []
|
| 77 |
+
for chunk in split(text):
|
| 78 |
+
for w, g in groupby(chunk, column_width):
|
| 79 |
+
if w == 1:
|
| 80 |
+
chunks.extend(split(''.join(g)))
|
| 81 |
+
else:
|
| 82 |
+
chunks.extend(list(g))
|
| 83 |
+
return chunks
|
| 84 |
+
|
| 85 |
+
def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width):
|
| 86 |
+
space_left = max(width - cur_len, 1)
|
| 87 |
+
if self.break_long_words:
|
| 88 |
+
l, r = self._break_word(reversed_chunks[-1], space_left)
|
| 89 |
+
cur_line.append(l)
|
| 90 |
+
reversed_chunks[-1] = r
|
| 91 |
+
|
| 92 |
+
elif not cur_line:
|
| 93 |
+
cur_line.append(reversed_chunks.pop())
|
| 94 |
+
|
| 95 |
+
def fw_wrap(text,width=50):
|
| 96 |
+
w = TextWrapper(width=width)
|
| 97 |
+
return w.wrap(text)
|