Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/userp/tpg.py

108 lines
4.4 KiB
Python
Raw Normal View History

2020-06-13 12:43:43 +00:00
# -*- coding: utf-8 -*-
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from os.path import abspath
2020-08-12 16:01:34 +00:00
def tpg(favicon, wikiname, username, gender, registertime, contributionwikis, createcount, editcount, deletecount,
patrolcount, sitetop, globaltop, wikipoint, blockbyuser='0', blocktimestamp1='0', blocktimestamp2='0',
blockreason='0', bantype='None'):
font = ImageFont.truetype(abspath('./assests/SourceHanSansCN-Normal.ttf'), 40)
2020-08-12 16:01:34 +00:00
font1 = ImageFont.truetype(abspath('./assests/SourceHanSansCN-Normal.ttf'), 70)
2020-08-07 14:27:37 +00:00
if bantype == 'None':
img = Image.open(abspath('./assests/base.png'))
elif bantype == 'Y' or bantype == 'YN':
img = Image.open(abspath('./assests/ban.png'))
2020-06-13 12:43:43 +00:00
img2 = Image.open(favicon)
img3 = Image.new("RGBA", img.size)
w, h = img2.size
w = int(w)
h = int(h)
try:
2020-08-12 16:01:34 +00:00
img2 = img2.resize((int(w / (w // 100)), int(h / (h // 100))))
2020-08-21 12:40:05 +00:00
except Exception:
2020-06-13 12:43:43 +00:00
pass
2020-08-12 16:01:34 +00:00
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:31:54 +00:00
try:
img21.alpha_composite(img2.convert("RGBA"), (int((W - w) / 2), int((H - h) / 2)))
except Exception:
try:
img21.alpha_composite(img2.convert("RGBA"), (int(-(W - w) / 2), int((H - h) / 2)))
except Exception:
try:
img21.alpha_composite(img2.convert("RGBA"), (int((W - w) / 2), int(-(H - h) / 2)))
except Exception:
img21.alpha_composite(img2.convert("RGBA"), (int(-(W - w) / 2), int(-(H - h) / 2)))
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':
img8 = Image.open(abspath('./assests/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':
draw.text((200, 1439), '' + str(blockbyuser) + '封禁,', '#ffffff', font=font)
2020-08-12 16:01:34 +00:00
draw.text((200, 1489), '时间从' + str(blocktimestamp1) + 'UTC+8', '#ffffff', font=font)
draw.text((200, 1539), '' + 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)
2020-08-12 16:01:34 +00:00
img3.save(abspath('./assests/usercard/' + username + '.png'))