Refactor default.py to improve profile card layout and styling, including adjustments to stroke width, positioning of elements, and enhancements to the glass morphism effect. Update pyproject.toml to maintain consistent formatting and remove unnecessary lines.
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run
This commit is contained in:
parent
18664d75c3
commit
7b8b81c777
2 changed files with 58 additions and 73 deletions
|
@ -191,42 +191,39 @@ def generate_default_profile(
|
||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
default_fill = (255, 255, 255) # Default fill color for text
|
default_fill = (255, 255, 255) # Default fill color for text
|
||||||
stroke_width = 2 # Width of the stroke around text
|
stroke_width = 1 # Reduced stroke width for cleaner look
|
||||||
|
|
||||||
if square:
|
# Card dimensions and layout
|
||||||
desired_card_size = (450, 450)
|
desired_card_size = (1050, 320) # Keep consistent size
|
||||||
else:
|
|
||||||
# Slightly increase height to accommodate larger fonts
|
# Define profile picture size and positions - moved to right side
|
||||||
desired_card_size = (1050, 320)
|
pfp_size = (220, 220) # Slightly smaller profile picture
|
||||||
|
pfp_x = desired_card_size[0] - pfp_size[0] - 50 # Right side positioning
|
||||||
# Define profile picture size and positions
|
|
||||||
pfp_size = (270, 270) # Slightly smaller profile picture
|
|
||||||
pfp_x = 55
|
|
||||||
pfp_y = (desired_card_size[1] - pfp_size[1]) // 2
|
pfp_y = (desired_card_size[1] - pfp_size[1]) // 2
|
||||||
circle_x = pfp_x
|
circle_x = pfp_x
|
||||||
circle_y = pfp_y
|
circle_y = pfp_y
|
||||||
|
|
||||||
# Define the stats area with a modern glass effect
|
# Define the stats area with a modern glass effect - adjusted for left side
|
||||||
stats_area = (
|
stats_area = (
|
||||||
15, # x1 - Start from left edge with small padding
|
25, # x1 - Start from left edge with small padding
|
||||||
15, # y1 - Start near top
|
20, # y1 - Start near top
|
||||||
1035, # x2 - End near right edge
|
desired_card_size[0] - pfp_size[0] - 100, # x2 - End before profile picture
|
||||||
305 # y2 - Adjusted height
|
desired_card_size[1] - 20 # y2 - End near bottom
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create the stats layer with glass effect
|
# Create the stats layer with glass effect
|
||||||
stats_layer = Image.new("RGBA", desired_card_size, (0, 0, 0, 0))
|
stats_layer = Image.new("RGBA", desired_card_size, (0, 0, 0, 0))
|
||||||
|
|
||||||
# Create a modern glass morphism effect for entire background
|
# Create a modern glass morphism effect
|
||||||
glass = Image.new("RGBA", desired_card_size, (0, 0, 0, 0))
|
glass = Image.new("RGBA", desired_card_size, (0, 0, 0, 0))
|
||||||
glass_draw = ImageDraw.Draw(glass)
|
glass_draw = ImageDraw.Draw(glass)
|
||||||
glass_draw.rounded_rectangle(stats_area, radius=25, fill=(0, 0, 0, 100)) # Darker, semi-transparent background
|
glass_draw.rounded_rectangle(stats_area, radius=25, fill=(0, 0, 0, 80)) # Lighter, more modern transparency
|
||||||
|
|
||||||
# Add a subtle gradient overlay for depth
|
# Add a subtle gradient overlay for depth
|
||||||
gradient = Image.new("RGBA", desired_card_size, (0, 0, 0, 0))
|
gradient = Image.new("RGBA", desired_card_size, (0, 0, 0, 0))
|
||||||
gradient_draw = ImageDraw.Draw(gradient)
|
gradient_draw = ImageDraw.Draw(gradient)
|
||||||
for i in range(40):
|
for i in range(40):
|
||||||
opacity = int(35 * (1 - i/40)) # Reduced opacity for subtler effect
|
opacity = int(25 * (1 - i/40)) # Even subtler effect
|
||||||
gradient_draw.rounded_rectangle(
|
gradient_draw.rounded_rectangle(
|
||||||
(stats_area[0], stats_area[1]+i, stats_area[2], stats_area[3]),
|
(stats_area[0], stats_area[1]+i, stats_area[2], stats_area[3]),
|
||||||
radius=25,
|
radius=25,
|
||||||
|
@ -236,16 +233,6 @@ def generate_default_profile(
|
||||||
# Composite the glass effect
|
# Composite the glass effect
|
||||||
stats_layer = Image.alpha_composite(stats_layer, glass)
|
stats_layer = Image.alpha_composite(stats_layer, glass)
|
||||||
stats_layer = Image.alpha_composite(stats_layer, gradient)
|
stats_layer = Image.alpha_composite(stats_layer, gradient)
|
||||||
|
|
||||||
# Add a subtle border glow
|
|
||||||
border_draw = ImageDraw.Draw(stats_layer)
|
|
||||||
for i in range(3):
|
|
||||||
border_draw.rounded_rectangle(
|
|
||||||
(stats_area[0]-i, stats_area[1]-i, stats_area[2]+i, stats_area[3]+i),
|
|
||||||
radius=25,
|
|
||||||
outline=(255, 255, 255, 80-i*25), # Lighter border
|
|
||||||
width=1
|
|
||||||
)
|
|
||||||
|
|
||||||
# Draw stats with improved styling
|
# Draw stats with improved styling
|
||||||
draw = ImageDraw.Draw(stats_layer)
|
draw = ImageDraw.Draw(stats_layer)
|
||||||
|
@ -256,58 +243,59 @@ def generate_default_profile(
|
||||||
level_text = f"P{prestige} • {level_text}"
|
level_text = f"P{prestige} • {level_text}"
|
||||||
|
|
||||||
# Use larger font for level display
|
# Use larger font for level display
|
||||||
level_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 56) # Increased size
|
level_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 64) # Increased size
|
||||||
level_y = stats_area[1] + 15
|
level_y = stats_area[1] + 20
|
||||||
|
|
||||||
# Add subtle text shadow for depth
|
# Add subtle text shadow for depth
|
||||||
shadow_offset = 2
|
shadow_offset = 2
|
||||||
|
level_x = stats_area[0] + 30 # Move level text to left side
|
||||||
|
|
||||||
|
# Draw level text with improved shadow
|
||||||
draw.text(
|
draw.text(
|
||||||
(stats_area[0] + 340 + shadow_offset, level_y + shadow_offset), # Adjusted x position
|
(level_x + shadow_offset, level_y + shadow_offset),
|
||||||
level_text,
|
level_text,
|
||||||
font=level_font,
|
font=level_font,
|
||||||
fill=(0, 0, 0, 80) # Reduced shadow opacity
|
fill=(0, 0, 0, 60) # More subtle shadow
|
||||||
)
|
)
|
||||||
draw.text(
|
draw.text(
|
||||||
(stats_area[0] + 340, level_y), # Adjusted x position
|
(level_x, level_y),
|
||||||
level_text,
|
level_text,
|
||||||
font=level_font,
|
font=level_font,
|
||||||
fill=user_color
|
fill=user_color
|
||||||
)
|
)
|
||||||
|
|
||||||
# Stats section with improved layout and larger fonts
|
# Stats section with improved layout
|
||||||
title_font_size = 28 # Increased from 26
|
title_font_size = 26 # Slightly smaller for better hierarchy
|
||||||
value_font_size = 32 # Increased from 30
|
value_font_size = 30 # Kept larger for emphasis
|
||||||
title_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), title_font_size)
|
title_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), title_font_size)
|
||||||
value_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), value_font_size)
|
value_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), value_font_size)
|
||||||
spacing = 45 # Increased spacing
|
spacing = 50 # Increased spacing between stats
|
||||||
|
|
||||||
# Starting positions
|
# Starting positions - moved down and left
|
||||||
start_x = stats_area[0] + 340 # Adjusted x position
|
start_x = stats_area[0] + 40
|
||||||
start_y = level_y + 75
|
start_y = level_y + 100 # More space after level text
|
||||||
|
|
||||||
# Helper function for stat rendering with improved spacing
|
# Helper function for stat rendering with improved spacing
|
||||||
def draw_stat(x_pos, y_pos, icon, title, value, color=stat_color):
|
def draw_stat(x_pos, y_pos, icon, title, value, color=stat_color):
|
||||||
# Draw icon with glow effect
|
# Draw icon with subtle glow
|
||||||
for offset in [(1,1), (-1,-1), (1,-1), (-1,1)]:
|
draw.text((x_pos, y_pos), icon, font=value_font, fill=color)
|
||||||
draw.text((x_pos + offset[0], y_pos + offset[1] + 2), icon, font=value_font, fill=(255, 255, 255, 30))
|
|
||||||
draw.text((x_pos, y_pos + 2), icon, font=value_font, fill=color)
|
|
||||||
|
|
||||||
# Draw title with modern styling
|
# Draw title with modern styling
|
||||||
title_x = x_pos + 40 # Increased spacing after icon
|
title_x = x_pos + 40
|
||||||
draw.text((title_x, y_pos), f"{title}:", font=title_font, fill=(220, 220, 220))
|
draw.text((title_x, y_pos), f"{title}:", font=title_font, fill=(200, 200, 200)) # Slightly dimmer
|
||||||
|
|
||||||
# Calculate value position
|
# Calculate value position
|
||||||
title_width = draw.textlength(f"{title}:", font=title_font)
|
title_width = draw.textlength(f"{title}:", font=title_font)
|
||||||
value_x = title_x + title_width + 10 # Increased spacing
|
value_x = title_x + title_width + 15
|
||||||
|
|
||||||
# Draw value with subtle shadow
|
# Draw value with subtle shadow
|
||||||
draw.text((value_x + 1, y_pos + 1), value, font=value_font, fill=(0, 0, 0, 60))
|
draw.text((value_x + 1, y_pos + 1), value, font=value_font, fill=(0, 0, 0, 40))
|
||||||
draw.text((value_x, y_pos), value, font=value_font, fill=color)
|
draw.text((value_x, y_pos), value, font=value_font, fill=color)
|
||||||
return spacing
|
return spacing
|
||||||
|
|
||||||
# Draw stats in two columns with better spacing
|
# Draw stats in two columns with better spacing
|
||||||
left_column_x = start_x
|
left_column_x = start_x
|
||||||
right_column_x = stats_area[0] + 340 # Adjusted for larger text
|
right_column_x = start_x + 380 # Increased column separation
|
||||||
current_y = start_y
|
current_y = start_y
|
||||||
|
|
||||||
# Left column stats
|
# Left column stats
|
||||||
|
@ -321,24 +309,24 @@ def generate_default_profile(
|
||||||
current_y += draw_stat(right_column_x, current_y, "💰", "Balance", f"{humanize_number(balance)} {currency_name}")
|
current_y += draw_stat(right_column_x, current_y, "💰", "Balance", f"{humanize_number(balance)} {currency_name}")
|
||||||
current_y += draw_stat(right_column_x, current_y, "🏆", "Rank", f"#{humanize_number(position)}")
|
current_y += draw_stat(right_column_x, current_y, "🏆", "Rank", f"#{humanize_number(position)}")
|
||||||
|
|
||||||
# Calculate progress percentage correctly
|
# Progress bar with modern design - moved to bottom
|
||||||
progress = (current_xp - previous_xp) / (next_xp - previous_xp) if next_xp > previous_xp else 0
|
bar_width = stats_area[2] - stats_area[0] - 60 # Full width progress bar
|
||||||
progress = max(0, min(1, progress)) # Ensure progress is between 0 and 1
|
bar_height = 25 # Slightly thinner
|
||||||
|
bar_x = stats_area[0] + 30
|
||||||
|
bar_y = stats_area[3] - 60 # Move up from bottom
|
||||||
|
|
||||||
# Progress bar with modern design
|
# Progress bar background with modern blur effect
|
||||||
bar_width = stats_area[2] - stats_area[0] - 40 # Slightly narrower
|
|
||||||
bar_height = 30
|
|
||||||
bar_x = stats_area[0] + 20
|
|
||||||
bar_y = stats_area[3] - 60 # Move up slightly
|
|
||||||
|
|
||||||
# Progress bar background
|
|
||||||
draw.rounded_rectangle(
|
draw.rounded_rectangle(
|
||||||
(bar_x, bar_y, bar_x + bar_width, bar_y + bar_height),
|
(bar_x, bar_y, bar_x + bar_width, bar_y + bar_height),
|
||||||
radius=bar_height//2,
|
radius=bar_height//2,
|
||||||
fill=(0, 0, 0, 60) # Semi-transparent background
|
fill=(0, 0, 0, 40) # Very subtle background
|
||||||
)
|
)
|
||||||
|
|
||||||
# Progress bar fill
|
# Calculate progress
|
||||||
|
progress = (current_xp - previous_xp) / (next_xp - previous_xp) if next_xp > previous_xp else 0
|
||||||
|
progress = max(0, min(1, progress)) # Ensure progress is between 0 and 1
|
||||||
|
|
||||||
|
# Progress bar fill with gradient effect
|
||||||
if progress > 0:
|
if progress > 0:
|
||||||
progress_width = int(bar_width * progress)
|
progress_width = int(bar_width * progress)
|
||||||
draw.rounded_rectangle(
|
draw.rounded_rectangle(
|
||||||
|
@ -348,25 +336,25 @@ def generate_default_profile(
|
||||||
)
|
)
|
||||||
|
|
||||||
# XP Text with improved visibility
|
# XP Text with improved visibility
|
||||||
xp_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 20)
|
xp_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 22)
|
||||||
xp_text = f"XP: {humanize_number(current_xp)} / {humanize_number(next_xp)}"
|
xp_text = f"XP: {humanize_number(current_xp)} / {humanize_number(next_xp)}"
|
||||||
xp_w = draw.textlength(xp_text, font=xp_font)
|
xp_w = draw.textlength(xp_text, font=xp_font)
|
||||||
xp_x = bar_x + (bar_width - xp_w) / 2
|
xp_x = bar_x + (bar_width - xp_w) / 2
|
||||||
xp_y = bar_y - 25
|
xp_y = bar_y - 30
|
||||||
|
|
||||||
# Draw XP text with shadow for better visibility
|
# Draw XP text with improved shadow
|
||||||
draw.text((xp_x + 1, xp_y + 1), xp_text, font=xp_font, fill=(0, 0, 0, 128))
|
draw.text((xp_x + 1, xp_y + 1), xp_text, font=xp_font, fill=(0, 0, 0, 80))
|
||||||
draw.text((xp_x, xp_y), xp_text, font=xp_font, fill=(255, 255, 255))
|
draw.text((xp_x, xp_y), xp_text, font=xp_font, fill=(255, 255, 255))
|
||||||
|
|
||||||
# Progress percentage with improved visibility
|
# Progress percentage with improved visibility
|
||||||
percent_text = f"{int(progress * 100)}%"
|
percent_text = f"{int(progress * 100)}%"
|
||||||
percent_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 24)
|
percent_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 20)
|
||||||
percent_w = draw.textlength(percent_text, font=percent_font)
|
percent_w = draw.textlength(percent_text, font=percent_font)
|
||||||
percent_x = bar_x + progress_width - percent_w - 10
|
percent_x = bar_x + progress_width - percent_w - 10
|
||||||
percent_y = bar_y + 3
|
percent_y = bar_y + 2
|
||||||
|
|
||||||
# Draw percentage with shadow for better visibility
|
# Draw percentage with improved shadow
|
||||||
draw.text((percent_x + 1, percent_y + 1), percent_text, font=percent_font, fill=(0, 0, 0, 128))
|
draw.text((percent_x + 1, percent_y + 1), percent_text, font=percent_font, fill=(0, 0, 0, 80))
|
||||||
draw.text((percent_x, percent_y), percent_text, font=percent_font, fill=(255, 255, 255))
|
draw.text((percent_x, percent_y), percent_text, font=percent_font, fill=(255, 255, 255))
|
||||||
|
|
||||||
# Composite the layers
|
# Composite the layers
|
||||||
|
|
|
@ -6,7 +6,4 @@
|
||||||
[tool.black]
|
[tool.black]
|
||||||
line-length = 99
|
line-length = 99
|
||||||
target-version = ['py38']
|
target-version = ['py38']
|
||||||
include = '\.pyi?$'
|
include = '\.pyi?$'
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
|
||||||
python = ">=3.8.1,<4.0"
|
|
Loading…
Add table
Reference in a new issue