From 7b8b81c7772f721386f057ca4d4828e7b78cda38 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 26 May 2025 21:47:40 -0400 Subject: [PATCH] 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. --- levelup/generator/styles/default.py | 126 +++++++++++++--------------- pyproject.toml | 5 +- 2 files changed, 58 insertions(+), 73 deletions(-) diff --git a/levelup/generator/styles/default.py b/levelup/generator/styles/default.py index 93bdec8..ae662a5 100644 --- a/levelup/generator/styles/default.py +++ b/levelup/generator/styles/default.py @@ -191,42 +191,39 @@ def generate_default_profile( # Setup 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: - desired_card_size = (450, 450) - else: - # Slightly increase height to accommodate larger fonts - desired_card_size = (1050, 320) - - # Define profile picture size and positions - pfp_size = (270, 270) # Slightly smaller profile picture - pfp_x = 55 + # Card dimensions and layout + desired_card_size = (1050, 320) # Keep consistent size + + # Define profile picture size and positions - moved to right side + pfp_size = (220, 220) # Slightly smaller profile picture + pfp_x = desired_card_size[0] - pfp_size[0] - 50 # Right side positioning pfp_y = (desired_card_size[1] - pfp_size[1]) // 2 circle_x = pfp_x 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 = ( - 15, # x1 - Start from left edge with small padding - 15, # y1 - Start near top - 1035, # x2 - End near right edge - 305 # y2 - Adjusted height + 25, # x1 - Start from left edge with small padding + 20, # y1 - Start near top + desired_card_size[0] - pfp_size[0] - 100, # x2 - End before profile picture + desired_card_size[1] - 20 # y2 - End near bottom ) # Create the stats layer with glass effect 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_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 gradient = Image.new("RGBA", desired_card_size, (0, 0, 0, 0)) gradient_draw = ImageDraw.Draw(gradient) 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( (stats_area[0], stats_area[1]+i, stats_area[2], stats_area[3]), radius=25, @@ -236,16 +233,6 @@ def generate_default_profile( # Composite the glass effect stats_layer = Image.alpha_composite(stats_layer, glass) 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 = ImageDraw.Draw(stats_layer) @@ -256,58 +243,59 @@ def generate_default_profile( level_text = f"P{prestige} • {level_text}" # Use larger font for level display - level_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 56) # Increased size - level_y = stats_area[1] + 15 + level_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 64) # Increased size + level_y = stats_area[1] + 20 # Add subtle text shadow for depth shadow_offset = 2 + level_x = stats_area[0] + 30 # Move level text to left side + + # Draw level text with improved shadow 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, font=level_font, - fill=(0, 0, 0, 80) # Reduced shadow opacity + fill=(0, 0, 0, 60) # More subtle shadow ) draw.text( - (stats_area[0] + 340, level_y), # Adjusted x position + (level_x, level_y), level_text, font=level_font, fill=user_color ) - # Stats section with improved layout and larger fonts - title_font_size = 28 # Increased from 26 - value_font_size = 32 # Increased from 30 + # Stats section with improved layout + title_font_size = 26 # Slightly smaller for better hierarchy + value_font_size = 30 # Kept larger for emphasis 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) - spacing = 45 # Increased spacing + spacing = 50 # Increased spacing between stats - # Starting positions - start_x = stats_area[0] + 340 # Adjusted x position - start_y = level_y + 75 + # Starting positions - moved down and left + start_x = stats_area[0] + 40 + start_y = level_y + 100 # More space after level text # Helper function for stat rendering with improved spacing def draw_stat(x_pos, y_pos, icon, title, value, color=stat_color): - # Draw icon with glow effect - for offset in [(1,1), (-1,-1), (1,-1), (-1,1)]: - 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 icon with subtle glow + draw.text((x_pos, y_pos), icon, font=value_font, fill=color) # Draw title with modern styling - title_x = x_pos + 40 # Increased spacing after icon - draw.text((title_x, y_pos), f"{title}:", font=title_font, fill=(220, 220, 220)) + title_x = x_pos + 40 + draw.text((title_x, y_pos), f"{title}:", font=title_font, fill=(200, 200, 200)) # Slightly dimmer # Calculate value position 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.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) return spacing # Draw stats in two columns with better spacing 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 # 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, "🏆", "Rank", f"#{humanize_number(position)}") - # Calculate progress percentage correctly - 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 with modern design - moved to bottom + bar_width = stats_area[2] - stats_area[0] - 60 # Full width progress bar + 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 - 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 + # Progress bar background with modern blur effect draw.rounded_rectangle( (bar_x, bar_y, bar_x + bar_width, bar_y + bar_height), 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: progress_width = int(bar_width * progress) draw.rounded_rectangle( @@ -348,25 +336,25 @@ def generate_default_profile( ) # 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_w = draw.textlength(xp_text, font=xp_font) 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.text((xp_x + 1, xp_y + 1), xp_text, font=xp_font, fill=(0, 0, 0, 128)) + # Draw XP text with improved shadow + 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)) # Progress percentage with improved visibility 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_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.text((percent_x + 1, percent_y + 1), percent_text, font=percent_font, fill=(0, 0, 0, 128)) + # Draw percentage with improved shadow + 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)) # Composite the layers diff --git a/pyproject.toml b/pyproject.toml index 1e98cd9..734bebf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,4 @@ [tool.black] line-length = 99 target-version = ['py38'] - include = '\.pyi?$' - -[tool.poetry.dependencies] -python = ">=3.8.1,<4.0" + include = '\.pyi?$' \ No newline at end of file