2020-06-13 12:43:43 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2021-02-01 15:13:11 +00:00
|
|
|
|
import uuid
|
2020-09-19 10:35:13 +00:00
|
|
|
|
from os.path import abspath
|
|
|
|
|
|
2020-06-13 12:43:43 +00:00
|
|
|
|
from PIL import Image
|
|
|
|
|
from PIL import ImageDraw
|
|
|
|
|
from PIL import ImageFont
|
2020-08-12 16:01:34 +00:00
|
|
|
|
|
|
|
|
|
|
2023-06-17 11:52:42 +00:00
|
|
|
|
def tpg(msg, favicon, wikiname, username, gender, registertime, contributionwikis, createcount, editcount, deletecount,
|
2020-08-12 16:01:34 +00:00
|
|
|
|
patrolcount, sitetop, globaltop, wikipoint, blockbyuser='0', blocktimestamp1='0', blocktimestamp2='0',
|
2022-07-26 18:07:09 +00:00
|
|
|
|
blockreason='0', bantype=None):
|
2020-09-20 10:36:32 +00:00
|
|
|
|
font = ImageFont.truetype(abspath('./assets/SourceHanSansCN-Normal.ttf'), 40)
|
|
|
|
|
font1 = ImageFont.truetype(abspath('./assets/SourceHanSansCN-Normal.ttf'), 70)
|
2022-07-26 18:07:09 +00:00
|
|
|
|
if bantype is None:
|
2020-09-20 10:36:32 +00:00
|
|
|
|
img = Image.open(abspath('./assets/base.png'))
|
2020-08-07 14:27:37 +00:00
|
|
|
|
elif bantype == 'Y' or bantype == 'YN':
|
2020-09-20 10:36:32 +00:00
|
|
|
|
img = Image.open(abspath('./assets/ban.png'))
|
2021-04-25 14:44:44 +00:00
|
|
|
|
if favicon:
|
|
|
|
|
img2 = Image.open(favicon)
|
2021-04-25 15:03:58 +00:00
|
|
|
|
else:
|
|
|
|
|
img2 = Image.new("RGBA", (100, 100))
|
|
|
|
|
img3 = Image.new("RGBA", img.size)
|
|
|
|
|
w, h = img2.size
|
|
|
|
|
w = int(w)
|
|
|
|
|
h = int(h)
|
|
|
|
|
try:
|
|
|
|
|
img2 = img2.resize((int(w / (w // 100)), int(h / (h // 100))))
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
img3.paste(img, (0, 0))
|
2020-06-13 12:43:43 +00:00
|
|
|
|
|
2020-08-12 16:01:34 +00:00
|
|
|
|
img21 = Image.new("RGBA", (200, 200))
|
2020-06-13 12:43:43 +00:00
|
|
|
|
W = 200
|
|
|
|
|
H = 200
|
2020-08-12 16:01:34 +00:00
|
|
|
|
w, h = img2.size
|
2020-08-26 13:57:08 +00:00
|
|
|
|
wg = int((W - w) / 2)
|
|
|
|
|
hg = int((H - h) / 2)
|
|
|
|
|
if wg < 0:
|
|
|
|
|
wg = int((w - W) / 2)
|
|
|
|
|
if hg < 0:
|
|
|
|
|
hg = int((h - H) / 2)
|
2020-08-26 14:07:14 +00:00
|
|
|
|
img21.alpha_composite(img2.convert("RGBA"), (wg, hg))
|
2020-08-12 16:01:34 +00:00
|
|
|
|
img3.alpha_composite(img21, (95, 52))
|
2020-06-13 12:43:43 +00:00
|
|
|
|
draw = ImageDraw.Draw(img3)
|
|
|
|
|
draw.text((325, 120), str(wikiname), '#ffffff', font=font1)
|
|
|
|
|
draw.text((230, 295), str(username), '#ffffff', font=font1)
|
2020-08-12 16:01:34 +00:00
|
|
|
|
draw.text((617, 685), '(UTC+8)', '#ffffff', font=font)
|
2020-06-13 12:43:43 +00:00
|
|
|
|
|
2020-08-12 16:01:34 +00:00
|
|
|
|
img32 = Image.new("RGBA", (120, 40))
|
2020-06-13 12:43:43 +00:00
|
|
|
|
W = 120
|
|
|
|
|
draww = ImageDraw.Draw(img32)
|
2020-08-12 16:01:34 +00:00
|
|
|
|
w, h = draww.textsize(gender, font=font)
|
|
|
|
|
draww.text(((W - w - font.getoffset(gender)[0]) / 2, 0), gender, "#ffffff", font=font)
|
|
|
|
|
img3.alpha_composite(img32, (194, 635))
|
2020-06-13 12:43:43 +00:00
|
|
|
|
|
|
|
|
|
img31 = Image.new("RGBA", (1280, 40))
|
|
|
|
|
W = 1280
|
|
|
|
|
draww = ImageDraw.Draw(img31)
|
|
|
|
|
w, h = draww.textsize(registertime, font=font)
|
|
|
|
|
draww.text(((W - w - font.getoffset(registertime)[0]) / 2, 0), registertime, "#ffffff", font=font)
|
|
|
|
|
img3.alpha_composite(img31, (80, 635))
|
|
|
|
|
|
|
|
|
|
draw.text((800, 785), str(contributionwikis), '#ffffff', font=font)
|
|
|
|
|
|
|
|
|
|
img4 = Image.new("RGBA", (280, 40))
|
|
|
|
|
W = 280
|
|
|
|
|
draww = ImageDraw.Draw(img4)
|
|
|
|
|
w, h = draww.textsize(createcount, font=font)
|
|
|
|
|
draww.text(((W - w - font.getoffset(createcount)[0]) / 2, 0), createcount, "#ffffff", font=font)
|
|
|
|
|
img3.alpha_composite(img4, (115, 960))
|
|
|
|
|
|
|
|
|
|
img5 = Image.new("RGBA", (280, 40))
|
|
|
|
|
draww = ImageDraw.Draw(img5)
|
|
|
|
|
w, h = draww.textsize(editcount, font=font)
|
|
|
|
|
draww.text(((W - w - font.getoffset(editcount)[0]) / 2, 0), editcount, "#ffffff", font=font)
|
|
|
|
|
img3.alpha_composite(img5, (295, 960))
|
|
|
|
|
|
|
|
|
|
img6 = Image.new("RGBA", (280, 40))
|
|
|
|
|
draww = ImageDraw.Draw(img6)
|
|
|
|
|
w, h = draww.textsize(deletecount, font=font)
|
|
|
|
|
draww.text(((W - w - font.getoffset(deletecount)[0]) / 2, 0), deletecount, "#ffffff", font=font)
|
|
|
|
|
img3.alpha_composite(img6, (475, 960))
|
|
|
|
|
|
|
|
|
|
img7 = Image.new("RGBA", (280, 40))
|
|
|
|
|
draww = ImageDraw.Draw(img7)
|
|
|
|
|
w, h = draww.textsize(patrolcount, font=font)
|
|
|
|
|
draww.text(((W - w - font.getoffset(patrolcount)[0]) / 2, 0), patrolcount, "#ffffff", font=font)
|
|
|
|
|
img3.alpha_composite(img7, (655, 960))
|
2020-08-12 16:01:34 +00:00
|
|
|
|
|
2020-08-07 14:27:37 +00:00
|
|
|
|
if bantype == 'Y' or bantype == 'YN':
|
2020-09-20 10:36:32 +00:00
|
|
|
|
img8 = Image.open(abspath('./assets/Blocked.png'))
|
2020-08-12 16:01:34 +00:00
|
|
|
|
w, h = img8.size
|
2020-08-07 14:27:37 +00:00
|
|
|
|
w = int(w)
|
|
|
|
|
h = int(h)
|
2020-08-12 16:01:34 +00:00
|
|
|
|
img8 = img8.resize((int(w / 1.22), int(h / 1.22)))
|
|
|
|
|
img3.alpha_composite(img8.convert("RGBA"), (1, 100))
|
2020-06-13 12:43:43 +00:00
|
|
|
|
|
2020-08-12 16:01:34 +00:00
|
|
|
|
draw.text((625, 1095), str(wikipoint), '#ffffff', font=font)
|
2020-06-13 12:43:43 +00:00
|
|
|
|
draw.text((330, 1195), str(sitetop), '#ffffff', font=font)
|
|
|
|
|
draw.text((690, 1195), str(globaltop), '#ffffff', font=font)
|
2020-08-07 14:27:37 +00:00
|
|
|
|
|
|
|
|
|
if bantype == 'Y' or bantype == 'YN':
|
2023-06-17 11:52:42 +00:00
|
|
|
|
draw.text((200, 1439), msg.locale.t('user.message.user.blocked.blocked_by', blocked_by=str(blockbyuser)), '#ffffff', font=font)
|
|
|
|
|
draw.text((200, 1489), msg.locale.t('user.message.blocked.blocked_time') + str(blocktimestamp1) + '(UTC+8)', '#ffffff', font=font)
|
|
|
|
|
draw.text((200, 1539), msg.locale.t('user.message.blocked.blocked_expires') + str(blocktimestamp2), '#ffffff', font=font)
|
2020-08-07 14:27:37 +00:00
|
|
|
|
if bantype == 'Y':
|
|
|
|
|
draw.text((200, 1589), str(blockreason), '#ffffff', font=font)
|
2021-02-01 15:13:11 +00:00
|
|
|
|
filepath = abspath('./cache/' + str(uuid.uuid4()) + '.png')
|
2020-09-25 15:19:54 +00:00
|
|
|
|
img3.save(filepath)
|
|
|
|
|
return filepath
|