File size: 2,979 Bytes
f8c7305 a34a680 f8c7305 a34a680 f8c7305 c94f95b f8c7305 c94f95b f8c7305 a34a680 f8c7305 a34a680 f8c7305 a34a680 f8c7305 a34a680 f8c7305 a34a680 f8c7305 a34a680 f8c7305 c94f95b f8c7305 c94f95b f8c7305 c94f95b f8c7305 c94f95b f8c7305 c94f95b f8c7305 c94f95b a34a680 f8c7305 c94f95b f8c7305 c94f95b f8c7305 c94f95b f8c7305 c94f95b f8c7305 c94f95b f8c7305 c94f95b f8c7305 c94f95b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 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 |
from PIL import Image, ImageDraw, ImageFont, ImageEnhance
from pilmoji import Pilmoji
import textwrap
BASE_GRADATION_IMAGE = Image.open("images/base-gd.png")
BASE_WHITE_IMAGE = Image.open("images/base.png")
ICON = 'icon.png'
MPLUS_FONT_16 = ImageFont.truetype("fonts/MPLUSRounded1c-Regular.ttf", size=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):
draw = ImageDraw.Draw(im)
fontObj = ImageFont.truetype(font,size=size)
pure_lines = []
pos = 0
l = ""
if not disable_dot_wrap:
for char in string:
if char == "\n":
pure_lines.append(l)
l = ""
pos += 1
elif char == "ใ" or char == ",":
pure_lines.append(l + ("ใ" if char == "ใ" else ","))
l = ""
pos += 1
elif char == "ใ" or char == ".":
pure_lines.append(l + ("ใ" if char == "ใ" else "."))
l = ""
pos += 1
else:
l += char
pos += 1
if l:
pure_lines.append(l)
else:
pure_lines = string.split("\n")
lines = []
for line in pure_lines:
lines.extend(textwrap.wrap(line,width=split_len))
dy = 0
draw_lines = []
# ่จ็ฎ
for line in lines:
tsize = fontObj.getsize(line)
ofs_y = ofs[1] + dy
t_height = tsize[1]
x = int(ofs[0] - (tsize[0]/2))
draw_lines.append((x,ofs_y,line))
ofs_y += t_height + padding
dy += t_height + padding
# ๆ็ป
adj_y = -30 * (len(draw_lines)-1)
for dl in draw_lines:
with Pilmoji(im) as p:
p.text((dl[0],(adj_y + dl[1])),dl[2],font=fontObj,fill=color)
real_y = ofs[1] + adj_y + dy
return (0,dy,real_y)
content = "ใใใฏใในใใง็ๆใใใใใฎใงใ"
# ๅผ็จใใ
img = BASE_WHITE_IMAGE.copy()
icon = Image.open(ICON)
icon = icon.resize((720,720),Image.LANCZOS)
icon = icon.convert("L")
icon_filtered = ImageEnhance.Brightness(icon)
img.paste(icon_filtered.enhance(0.7),(0,0))
# ้ปใฐใฉใๅๆ
img.paste(BASE_GRADATION_IMAGE,(0,0),BASE_GRADATION_IMAGE)
# ใใญในใๅๆ
tx = ImageDraw.Draw(img)
# ๆ็ซ ๆ็ป
tsize_t = draw_text(img,(890,270),content,size=45,color=(255,255,255,255),split_len=16,auto_expand=True)
# ๅๅๆ็ป
uname = 'Taka005#6668'
name_y = tsize_t[2] + 40
tsize_name = draw_text(img,(890,name_y),uname,size=25,color=(255,255,255,255),split_len=25,disable_dot_wrap=True)
# IDๆ็ป
id = '000000000000'
id_y = name_y + tsize_name[1] + 4
tsize_id = draw_text(img,(890,id_y),f"({id})",size=18,color=(180,180,180,255),split_len=45,disable_dot_wrap=True)
# ใฏใฌใธใใ
tx.text((1125, 694),"TakasumiBOT#7189",font=MPLUS_FONT_16,fill=(120,120,120,255))
img.save("quote.png",quality=100) |