Taka005
commited on
Commit
·
c94f95b
1
Parent(s):
31ac6cb
修正
Browse files
main.py
CHANGED
|
@@ -9,10 +9,10 @@ ICON = 'icon.png'
|
|
| 9 |
|
| 10 |
MPLUS_FONT_16 = ImageFont.truetype("fonts/MPLUSRounded1c-Regular.ttf", size=16)
|
| 11 |
|
| 12 |
-
def draw_text(im,
|
| 13 |
|
| 14 |
draw = ImageDraw.Draw(im)
|
| 15 |
-
fontObj = ImageFont.truetype(font,
|
| 16 |
|
| 17 |
pure_lines = []
|
| 18 |
pos = 0
|
|
@@ -44,7 +44,7 @@ def draw_text(im, ofs, string, font="fonts/MPLUSRounded1c-Regular.ttf", size=16,
|
|
| 44 |
lines = []
|
| 45 |
|
| 46 |
for line in pure_lines:
|
| 47 |
-
lines.extend(textwrap.wrap(line,
|
| 48 |
|
| 49 |
dy = 0
|
| 50 |
|
|
@@ -59,7 +59,7 @@ def draw_text(im, ofs, string, font="fonts/MPLUSRounded1c-Regular.ttf", size=16,
|
|
| 59 |
t_height = tsize[1]
|
| 60 |
|
| 61 |
x = int(ofs[0] - (tsize[0]/2))
|
| 62 |
-
draw_lines.append((x,
|
| 63 |
ofs_y += t_height + padding
|
| 64 |
dy += t_height + padding
|
| 65 |
|
|
@@ -67,43 +67,43 @@ def draw_text(im, ofs, string, font="fonts/MPLUSRounded1c-Regular.ttf", size=16,
|
|
| 67 |
adj_y = -30 * (len(draw_lines)-1)
|
| 68 |
for dl in draw_lines:
|
| 69 |
with Pilmoji(im) as p:
|
| 70 |
-
p.text((dl[0],
|
| 71 |
|
| 72 |
real_y = ofs[1] + adj_y + dy
|
| 73 |
|
| 74 |
-
return (0,
|
| 75 |
|
| 76 |
-
content = "
|
| 77 |
# 引用する
|
| 78 |
img = BASE_WHITE_IMAGE.copy()
|
| 79 |
|
| 80 |
icon = Image.open(ICON)
|
| 81 |
-
icon = icon.resize((720,
|
| 82 |
icon = icon.convert("L")
|
| 83 |
icon_filtered = ImageEnhance.Brightness(icon)
|
| 84 |
|
| 85 |
-
img.paste(icon_filtered.enhance(0.7),
|
| 86 |
|
| 87 |
# 黒グラデ合成
|
| 88 |
-
img.paste(BASE_GRADATION_IMAGE,
|
| 89 |
|
| 90 |
# テキスト合成
|
| 91 |
tx = ImageDraw.Draw(img)
|
| 92 |
|
| 93 |
# 文章描画
|
| 94 |
-
tsize_t = draw_text(img,
|
| 95 |
|
| 96 |
# 名前描画
|
| 97 |
uname = 'Taka005#6668'
|
| 98 |
name_y = tsize_t[2] + 40
|
| 99 |
-
tsize_name = draw_text(img,
|
| 100 |
|
| 101 |
# ID描画
|
| 102 |
id = '000000000000'
|
| 103 |
id_y = name_y + tsize_name[1] + 4
|
| 104 |
-
tsize_id = draw_text(img,
|
| 105 |
|
| 106 |
# クレジット
|
| 107 |
-
tx.text((1125, 694),
|
| 108 |
|
| 109 |
-
img.save("quote.png",
|
|
|
|
| 9 |
|
| 10 |
MPLUS_FONT_16 = ImageFont.truetype("fonts/MPLUSRounded1c-Regular.ttf", size=16)
|
| 11 |
|
| 12 |
+
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):
|
| 13 |
|
| 14 |
draw = ImageDraw.Draw(im)
|
| 15 |
+
fontObj = ImageFont.truetype(font,size=size)
|
| 16 |
|
| 17 |
pure_lines = []
|
| 18 |
pos = 0
|
|
|
|
| 44 |
lines = []
|
| 45 |
|
| 46 |
for line in pure_lines:
|
| 47 |
+
lines.extend(textwrap.wrap(line,width=split_len))
|
| 48 |
|
| 49 |
dy = 0
|
| 50 |
|
|
|
|
| 59 |
t_height = tsize[1]
|
| 60 |
|
| 61 |
x = int(ofs[0] - (tsize[0]/2))
|
| 62 |
+
draw_lines.append((x,ofs_y,line))
|
| 63 |
ofs_y += t_height + padding
|
| 64 |
dy += t_height + padding
|
| 65 |
|
|
|
|
| 67 |
adj_y = -30 * (len(draw_lines)-1)
|
| 68 |
for dl in draw_lines:
|
| 69 |
with Pilmoji(im) as p:
|
| 70 |
+
p.text((dl[0],(adj_y + dl[1])),dl[2],font=fontObj,fill=color)
|
| 71 |
|
| 72 |
real_y = ofs[1] + adj_y + dy
|
| 73 |
|
| 74 |
+
return (0,dy,real_y)
|
| 75 |
|
| 76 |
+
content = "これはテストで生成されたものです"
|
| 77 |
# 引用する
|
| 78 |
img = BASE_WHITE_IMAGE.copy()
|
| 79 |
|
| 80 |
icon = Image.open(ICON)
|
| 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 |
|
| 87 |
# 黒グラデ合成
|
| 88 |
+
img.paste(BASE_GRADATION_IMAGE,(0,0),BASE_GRADATION_IMAGE)
|
| 89 |
|
| 90 |
# テキスト合成
|
| 91 |
tx = ImageDraw.Draw(img)
|
| 92 |
|
| 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 |
# 名前描画
|
| 97 |
uname = 'Taka005#6668'
|
| 98 |
name_y = tsize_t[2] + 40
|
| 99 |
+
tsize_name = draw_text(img,(890,name_y),uname,size=25,color=(255,255,255,255),split_len=25,disable_dot_wrap=True)
|
| 100 |
|
| 101 |
# ID描画
|
| 102 |
id = '000000000000'
|
| 103 |
id_y = name_y + tsize_name[1] + 4
|
| 104 |
+
tsize_id = draw_text(img,(890,id_y),f"({id})",size=18,color=(180,180,180,255),split_len=45,disable_dot_wrap=True)
|
| 105 |
|
| 106 |
# クレジット
|
| 107 |
+
tx.text((1125, 694),"TakasumiBOT#7189",font=MPLUS_FONT_16,fill=(120,120,120,255))
|
| 108 |
|
| 109 |
+
img.save("quote.png",quality=100)
|
quote.png
CHANGED
|
|