图片生成左边改动
This commit is contained in:
parent
3ca7f87801
commit
6e57d97cee
@ -76,7 +76,7 @@ async def builder(data, platform, property):
|
|||||||
spc_name = data_info.bestClass
|
spc_name = data_info.bestClass
|
||||||
best_class = Image.open(filepath + f"/img/specialist_img/{spc_name}.png").convert('RGBA')
|
best_class = Image.open(filepath + f"/img/specialist_img/{spc_name}.png").convert('RGBA')
|
||||||
best_class = png_resize(best_class, new_width=1920, new_height=1080)
|
best_class = png_resize(best_class, new_width=1920, new_height=1080)
|
||||||
data_image = image_paste(best_class, data_image, (450, 0))
|
data_image = image_paste(best_class, data_image, (395, 0))
|
||||||
|
|
||||||
# 4. 绘制武器板块
|
# 4. 绘制武器板块
|
||||||
# 绘制武器版面外框
|
# 绘制武器版面外框
|
||||||
@ -129,18 +129,18 @@ async def builder(data, platform, property):
|
|||||||
|
|
||||||
# 5.绘制载具板块
|
# 5.绘制载具板块
|
||||||
# 文字框
|
# 文字框
|
||||||
data_image = draw_rect(data_image, (575, 25, 1155, 120), 1, fill=(0, 0, 0, 300))
|
data_image = draw_rect(data_image, (575, 25, 1100, 120), 1, fill=(0, 0, 0, 300))
|
||||||
# 白横条
|
# 白横条
|
||||||
data_image = draw_rect(data_image, (575, 125, 1155, 145), 1, fill=(255, 255, 255, 300))
|
data_image = draw_rect(data_image, (575, 125, 1100, 145), 1, fill=(255, 255, 255, 300))
|
||||||
# 外框
|
# 外框
|
||||||
data_image = draw_rect(data_image, (575, 150, 1155, 1055), 1, fill=(50, 50, 50, 150))
|
data_image = draw_rect(data_image, (575, 150, 1100, 1055), 1, fill=(50, 50, 50, 150))
|
||||||
# 内框
|
# 内框
|
||||||
data_image = draw_rect(data_image, (578, 153, 1152, 1052), 5, fill=(0, 0, 0, 150))
|
data_image = draw_rect(data_image, (578, 153, 1097, 1052), 5, fill=(0, 0, 0, 150))
|
||||||
|
|
||||||
vehicle_text = "载 具 数 据"
|
vehicle_text = "载 具 数 据"
|
||||||
text_width = draw.textlength(vehicle_text, ch_text_font_title)
|
text_width = draw.textlength(vehicle_text, ch_text_font_title)
|
||||||
print(text_width)
|
print(text_width)
|
||||||
pos = (((575 - text_width) / 2) + 575, 30)
|
pos = (((525 - text_width) / 2) + 575, 30)
|
||||||
draw.text(pos, f'{vehicle_text}', fill="white", font=ch_text_font_title)
|
draw.text(pos, f'{vehicle_text}', fill="white", font=ch_text_font_title)
|
||||||
vehicle_en_text = "V E H I C L E S R E C O R D S"
|
vehicle_en_text = "V E H I C L E S R E C O R D S"
|
||||||
text_width = draw.textlength(vehicle_en_text, en_text_font_small)
|
text_width = draw.textlength(vehicle_en_text, en_text_font_small)
|
||||||
@ -151,27 +151,27 @@ async def builder(data, platform, property):
|
|||||||
# 粘贴载具图片
|
# 粘贴载具图片
|
||||||
data_image = image_paste(get_top_object_img(vehicle_list[i]).resize((240, 60)), data_image, (600, height + 5))
|
data_image = image_paste(get_top_object_img(vehicle_list[i]).resize((240, 60)), data_image, (600, height + 5))
|
||||||
# 绘制竖线
|
# 绘制竖线
|
||||||
draw.line([890, height - 5, 890, height + 130], fill="white", width=3, joint=None)
|
draw.line([835, height - 5, 835, height + 130], fill="white", width=3, joint=None)
|
||||||
# 获取文字的宽度
|
# 获取文字的宽度
|
||||||
vehicle_name = vehicle_list[i]["vehicleName"]
|
vehicle_name = vehicle_list[i]["vehicleName"]
|
||||||
width = draw.textlength(vehicle_name, en_text_font4) # 获取长度
|
width = draw.textlength(vehicle_name, en_text_font4) # 获取长度
|
||||||
|
|
||||||
# 绘制载具名称
|
# 绘制载具名称
|
||||||
draw.text((825 - width, height + 90), f'{vehicle_name}', fill="white", direction="rtl", font=en_text_font4)
|
draw.text((765 - width, height + 90), f'{vehicle_name}', fill="white", direction="rtl", font=en_text_font4)
|
||||||
|
|
||||||
# 绘制载具数据
|
# 绘制载具数据
|
||||||
draw.text((900, height), f'击杀人数:{vehicle_list[i]["kills"]}', fill="white", font=ch_text_font4)
|
draw.text((855, height), f'击杀人数:{vehicle_list[i]["kills"]}', fill="white", font=ch_text_font4)
|
||||||
draw.text((900, height + 45), f'摧毁载具:{vehicle_list[i]["vehiclesDestroyedWith"]}', fill="white",
|
draw.text((855, height + 45), f'摧毁载具:{vehicle_list[i]["vehiclesDestroyedWith"]}', fill="white",
|
||||||
font=ch_text_font4)
|
font=ch_text_font4)
|
||||||
draw.text((961, height + 90), f'KPM:{vehicle_list[i]["killsPerMinute"]}', fill="white", font=ch_text_font4)
|
draw.text((908, height + 90), f'KPM:{vehicle_list[i]["killsPerMinute"]}', fill="white", font=ch_text_font4)
|
||||||
# 绘制时长边框
|
# 绘制时长边框
|
||||||
data_image = draw_rect(data_image, (830, height + 90, 955, height + 130), 3, fill=(255, 255, 255, 1000))
|
data_image = draw_rect(data_image, (775, height + 90, 900, height + 130), 3, fill=(255, 255, 255, 1000))
|
||||||
data_image = draw_rect(data_image, (832, height + 92, 953, height + 128), 3, fill=(0, 0, 0, 1000))
|
data_image = draw_rect(data_image, (777, height + 92, 898, height + 128), 3, fill=(0, 0, 0, 1000))
|
||||||
data_image = draw_rect(data_image, (834, height + 94, 951, height + 126), 3, fill=(255, 255, 255, 1000))
|
data_image = draw_rect(data_image, (779, height + 94, 896, height + 126), 3, fill=(255, 255, 255, 1000))
|
||||||
# 绘制时长
|
# 绘制时长
|
||||||
play_time = f'{int(int(vehicle_list[i]["timeIn"]) / 3600 + 0.55)}H'
|
play_time = f'{int(int(vehicle_list[i]["timeIn"]) / 3600 + 0.55)}H'
|
||||||
font_width = draw.textlength(play_time, en_text_font4) # 获取长度
|
font_width = draw.textlength(play_time, en_text_font4) # 获取长度
|
||||||
draw.text((950 - font_width, height + 90), play_time,
|
draw.text((895 - font_width, height + 90), play_time,
|
||||||
fill="black",
|
fill="black",
|
||||||
font=en_text_font4)
|
font=en_text_font4)
|
||||||
height += 180
|
height += 180
|
||||||
@ -197,27 +197,27 @@ async def builder(data, platform, property):
|
|||||||
mvp = data_info.mvp
|
mvp = data_info.mvp
|
||||||
|
|
||||||
# 绘制 个人信息框
|
# 绘制 个人信息框
|
||||||
data_image = draw_rect(data_image, (1175, 690, 1700, 830), 1, fill=(50, 50, 50, 150))
|
data_image = draw_rect(data_image, (1120, 690, 1645, 830), 1, fill=(50, 50, 50, 150))
|
||||||
data_image = draw_rect(data_image, (1178, 693, 1697, 827), 5, fill=(0, 0, 0, 150))
|
data_image = draw_rect(data_image, (1123, 693, 1642, 827), 5, fill=(0, 0, 0, 150))
|
||||||
user_text = f"EA ID: {ea_id}"
|
user_text = f"EA ID: {ea_id}"
|
||||||
pos = (1190, 700)
|
pos = (1135, 700)
|
||||||
draw.text(pos, user_text, fill="white", font=en_text_font4)
|
draw.text(pos, user_text, fill="white", font=en_text_font4)
|
||||||
data_text1 = f"时长:{time_played}H"
|
data_text1 = f"时长:{time_played}H"
|
||||||
data_text2 = f"场次:{matches}"
|
data_text2 = f"场次:{matches}"
|
||||||
data_text3 = f"最佳:{mvp}"
|
data_text3 = f"最佳:{mvp}"
|
||||||
draw.text((1190, 775), data_text1, fill="white", font=ch_text_font_5)
|
draw.text((1135, 775), data_text1, fill="white", font=ch_text_font_5)
|
||||||
draw.text((1370, 775), data_text2, fill="white", font=ch_text_font_5)
|
draw.text((1315, 775), data_text2, fill="white", font=ch_text_font_5)
|
||||||
draw.text((1520, 775), data_text3, fill="white", font=ch_text_font_5)
|
draw.text((1456, 775), data_text3, fill="white", font=ch_text_font_5)
|
||||||
# 绘制专家信息
|
# 绘制专家信息
|
||||||
# 边框
|
# 边框
|
||||||
data_image = draw_rect(data_image, (1175, 831, 1700, 1055), 1, fill=(50, 50, 50, 150))
|
data_image = draw_rect(data_image, (1120, 831, 1645, 1055), 1, fill=(50, 50, 50, 150))
|
||||||
data_image = draw_rect(data_image, (1178, 834, 1697, 1052), 5, fill=(0, 0, 0, 150))
|
data_image = draw_rect(data_image, (1123, 834, 1642, 1052), 5, fill=(0, 0, 0, 150))
|
||||||
# 文字部分
|
# 文字部分
|
||||||
best_text = "最佳专家"
|
best_text = "最 佳 专 家"
|
||||||
best_text_width = draw.textlength(best_text, ch_text_font_h2)
|
best_text_width = draw.textlength(best_text, ch_text_font_h2)
|
||||||
# 分割线
|
# 分割线
|
||||||
draw.line([1510, 845, 1485, 1030], fill="white", width=3, joint=None)
|
draw.line([1455, 845, 1430, 1030], fill="white", width=3, joint=None)
|
||||||
draw.text((1495 - best_text_width, 860), best_text, fill="white", font=ch_text_font_h2)
|
draw.text((1440 - best_text_width, 860), best_text, fill="white", font=ch_text_font_h2)
|
||||||
best_class_data = sorted(data["classes"], key=lambda k: k['kills'], reverse=True)[0]
|
best_class_data = sorted(data["classes"], key=lambda k: k['kills'], reverse=True)[0]
|
||||||
best_class_name = classesList[spc_name]
|
best_class_name = classesList[spc_name]
|
||||||
best_kill = best_class_data['kills']
|
best_kill = best_class_data['kills']
|
||||||
@ -226,24 +226,29 @@ async def builder(data, platform, property):
|
|||||||
best_time = best_class_data['secondsPlayed']
|
best_time = best_class_data['secondsPlayed']
|
||||||
best_time = round(best_time / 3600, 2)
|
best_time = round(best_time / 3600, 2)
|
||||||
text_width_class_name = draw.textlength(best_class_name, ch_text_font_m)
|
text_width_class_name = draw.textlength(best_class_name, ch_text_font_m)
|
||||||
draw.text((1470 - text_width_class_name, 940), best_class_name,
|
draw.text((1415 - text_width_class_name, 963), best_class_name,
|
||||||
fill="white",
|
fill="white",
|
||||||
font=ch_text_font_m)
|
font=ch_text_font_m)
|
||||||
|
|
||||||
special_icon = await get_special_icon(best_class_data)
|
special_icon = await get_special_icon(best_class_data)
|
||||||
special_icon = png_resize(special_icon, new_width=50, new_height=50)
|
special_icon = png_resize(special_icon, new_width=75, new_height=75)
|
||||||
print(text_width_class_name)
|
print(text_width_class_name)
|
||||||
# paste方法不能处理浮点数
|
# paste方法不能处理浮点数
|
||||||
pos = (round(1470 - text_width_class_name - 60), 941)
|
pos = (round(1390 - text_width_class_name - 60), 950)
|
||||||
data_image = image_paste(special_icon, data_image, pos)
|
data_image = image_paste(special_icon, data_image, pos)
|
||||||
# 击杀/kd/kpm/时长
|
# 击杀/kd/kpm/时长
|
||||||
draw.text((1520, 860), f'K/D:{best_kd}', fill="white", font=ch_text_font_5)
|
draw.text((1465, 860), f'K/D:{best_kd}', fill="white", font=ch_text_font_5)
|
||||||
draw.text((1515, 900), f'KPM:{best_kpm}', fill="white", font=ch_text_font_5)
|
draw.text((1460, 900), f'KPM:{best_kpm}', fill="white", font=ch_text_font_5)
|
||||||
draw.text((1510, 940), f'击杀:{best_kill}', fill="white", font=ch_text_font_5)
|
draw.text((1455, 940), f'击杀:{best_kill}', fill="white", font=ch_text_font_5)
|
||||||
draw.text((1505, 980), f'时长:{best_time}H', fill="white", font=ch_text_font_5)
|
draw.text((1450, 980), f'时长:{best_time}H', fill="white", font=ch_text_font_5)
|
||||||
|
|
||||||
|
# 边框
|
||||||
|
data_image = draw_rect(data_image, (1120, 25, 1645, 120), 1, fill=(0, 0, 0, 300))
|
||||||
|
# 白横条
|
||||||
|
data_image = draw_rect(data_image, (1120, 125, 1645, 145), 1, fill=(255, 255, 255, 300))
|
||||||
|
|
||||||
# 分割线
|
# 分割线
|
||||||
draw.line([1725, 150, 1725, 1055], fill="white", width=3, joint=None)
|
draw.line([1670, 150, 1670, 1055], fill="white", width=5, joint=None)
|
||||||
# 7.生涯数据
|
# 7.生涯数据
|
||||||
# part1
|
# part1
|
||||||
kd = data_info.killDeath
|
kd = data_info.killDeath
|
||||||
@ -267,34 +272,40 @@ async def builder(data, platform, property):
|
|||||||
|
|
||||||
# 开始打印生涯数据
|
# 开始打印生涯数据
|
||||||
# 绘制边框
|
# 绘制边框
|
||||||
data_image = draw_rect(data_image, (1728, 150, 1895, 1055), 1, fill=(0, 0, 0, 150))
|
data_image = draw_rect(data_image, (1673, 150, 1895, 1055), 1, fill=(50, 50, 50, 150))
|
||||||
|
data_image = draw_rect(data_image, (1676, 153, 1892, 1052), 5, fill=(0, 0, 0, 150))
|
||||||
# part1
|
# part1
|
||||||
draw.text((1735, 165), f'K/D:{kd}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 165), f'K/D:{kd}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 222), f'真实K/D:{real_kd}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 222), f'真实K/D:{real_kd}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 279), f'击杀总数:{kd}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 279), f'击杀总数:{kd}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 336), f'载具击杀:{kd}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 336), f'载具击杀:{kd}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 393), f'死亡次数:{kd}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 393), f'死亡次数:{kd}', fill="white", font=ch_text_font_6)
|
||||||
# part1
|
# part1
|
||||||
# 分割线
|
# 分割线
|
||||||
data_image = await draw_point_line(data_image, (1740, 450), (1870, 450), line_spacing=5, line_length=30, line_width=2,
|
data_image = await draw_point_line(data_image, (1685, 450), (1870, 450), line_spacing=5, line_length=30, line_width=2,
|
||||||
line_color='white')
|
line_color='white')
|
||||||
|
|
||||||
draw.text((1735, 479), f'KPM:{kpm}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 479), f'KPM:{kpm}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 536), f'真实KPM:{real_kpm}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 536), f'真实KPM:{real_kpm}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 593), f'爆头率:{headshot}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 593), f'爆头率:{headshot}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 650), f'命中率:{acc}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 650), f'命中率:{acc}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 707), f'胜率:{win}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 707), f'胜率:{win}', fill="white", font=ch_text_font_6)
|
||||||
# part1
|
# part1
|
||||||
# 分割线
|
# 分割线
|
||||||
data_image = await draw_point_line(data_image, (1740, 764), (1870, 764), line_spacing=5, line_length=30,line_width=2,
|
data_image = await draw_point_line(data_image, (1685, 764), (1870, 764), line_spacing=5, line_length=30,line_width=2,
|
||||||
line_color='white')
|
line_color='white')
|
||||||
draw.text((1735, 793), f'AI击杀:{AI_kills}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 793), f'AI击杀:{AI_kills}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 850), f'场均击杀:{kills_per_match}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 850), f'场均击杀:{kills_per_match}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 907), f'急救:{revives}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 907), f'急救:{revives}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 964), f'标记:{spot}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 964), f'标记:{spot}', fill="white", font=ch_text_font_6)
|
||||||
draw.text((1735, 1021), f'摧毁载具:{vehicles_destroyed}', fill="white", font=ch_text_font_6)
|
draw.text((1680, 1021), f'摧毁载具:{vehicles_destroyed}', fill="white", font=ch_text_font_6)
|
||||||
|
|
||||||
# data_image.show()
|
# 粘贴game logo
|
||||||
|
logo = Image.open(filepath + "/img/bf2042_logo/bf2042logo.png").convert('RGBA')
|
||||||
|
logo = png_resize(logo, new_width=120, new_height=120)
|
||||||
|
data_image = image_paste(logo, data_image, (1775, 25))
|
||||||
|
|
||||||
|
data_image.show()
|
||||||
b_io = BytesIO()
|
b_io = BytesIO()
|
||||||
data_image.save(b_io, format="PNG")
|
data_image.save(b_io, format="PNG")
|
||||||
base64_str = 'base64://' + base64.b64encode(b_io.getvalue()).decode()
|
base64_str = 'base64://' + base64.b64encode(b_io.getvalue()).decode()
|
||||||
|
Loading…
Reference in New Issue
Block a user