-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGauntlet_leaderboard.py
81 lines (61 loc) · 2.94 KB
/
Gauntlet_leaderboard.py
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
import time
import requests,json
import io
from PIL import Image, ImageDraw, ImageFont
from build_finder import get_path
def seconds_to_minutes(seconds):
minutes, seconds = divmod(seconds, 60)
return f"{minutes:02d}:{seconds:02d}"
def get_text_dimensions(text_string, font):
ascent, descent = font.getmetrics()
text_width = font.getmask(text_string).getbbox()[2]
text_height = font.getmask(text_string).getbbox()[3] + descent
return (text_width, text_height)
def getImage_gauntlet_leaderboard(gauntlet_leaderboard_data,season_title,season_timeline):
try:
img = Image.open(get_path("Board_background.png"))
draw = ImageDraw.Draw(img)
font_path = "Roboto-Regular.ttf"
font = ImageFont.truetype(get_path(font_path), 24)
Title_font = ImageFont.truetype(get_path(font_path), 35)
season_title = f"Gauntlet season {season_title}"
Title_width,_ = get_text_dimensions(season_title,Title_font)
Timeline_width,_ = get_text_dimensions(season_timeline,Title_font)
Title_x = (1164 - Title_width) // 2
Timeline_x = (1164 - Timeline_width) // 2
draw.text((Title_x, 0), season_title, fill="white", font=Title_font)
draw.text((Timeline_x, 50), season_timeline, fill="#49be25", font=Title_font)
draw.text((48, 112), f"Rank", fill="white", font=font)
draw.text((180, 112), f"Guild", fill="white", font=font)
draw.text((800, 112), f"Level", fill="white", font=font)
draw.text((950, 112), f"Time Left", fill="white", font=font)
# Use a truetype font file (replace 'arial.ttf' with the path to your font file)
font = ImageFont.truetype(get_path(font_path), 30)
x, y = 150, 172
# Define custom coordinates for each piece of information
for i, guild_info in enumerate(gauntlet_leaderboard_data):
if i == 0:
fill = "#FFD700" # Gold
elif i == 1:
fill = "#E0E0E0" # Brighter Silver
elif i == 2:
fill = "#CD853F" # Brighter Bronze
else:
fill = "white"
# Draw guild_name
draw.text((66, y+28), f"{i+1}", fill=fill, font=font)
draw.text((x, y+5), f"{guild_info['guild_name']}", fill=fill, font=font)
# Draw guild_nameplate
draw.text((x, y + 45), f"{guild_info['guild_nameplate']}", fill=fill, font=font)
# Draw level
draw.text((800, y+20), f"{guild_info['level']}", fill=fill, font=font)
# Draw remaining_time
remaining_time = seconds_to_minutes(guild_info['remaining_sec'])
draw.text((960, y+20), f"{remaining_time}", fill=fill, font=font)
y += 130
img_bytes_io = io.BytesIO()
img.save(img_bytes_io, format='PNG')
img_bytes_io.seek(0)
return img_bytes_io
except requests.RequestException as e:
print(f"An error occurred: {e}")