Refine profile card generation in default.py by adjusting stats area dimensions, enhancing the glass effect with darker opacity, and improving the progress bar design for better visual clarity. Implement a final image composition step to ensure layers are correctly rendered.
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
6d9ac89123
commit
6c5f48fcd7
1 changed files with 24 additions and 15 deletions
|
@ -244,20 +244,20 @@ def generate_default_profile(
|
|||
stats_area = (
|
||||
400, # x1 - Start after profile picture
|
||||
20, # y1 - Start near top
|
||||
1000, # x2 - End near right edge
|
||||
1000 if not square else 430, # x2 - End near right edge
|
||||
430 # y2 - End near bottom
|
||||
)
|
||||
|
||||
# Create a semi-transparent background for stats
|
||||
glass = Image.new("RGBA", desired_card_size, (0, 0, 0, 0))
|
||||
glass_draw = ImageDraw.Draw(glass)
|
||||
glass_draw.rounded_rectangle(stats_area, radius=20, fill=(255, 255, 255, 30))
|
||||
glass_draw.rounded_rectangle(stats_area, radius=20, fill=(0, 0, 0, 80))
|
||||
|
||||
# Add a subtle gradient overlay
|
||||
gradient = Image.new("RGBA", desired_card_size, (0, 0, 0, 0))
|
||||
gradient_draw = ImageDraw.Draw(gradient)
|
||||
for i in range(20):
|
||||
opacity = int(255 * (1 - i/20))
|
||||
opacity = int(80 * (1 - i/20))
|
||||
gradient_draw.rounded_rectangle(
|
||||
(stats_area[0], stats_area[1]+i, stats_area[2], stats_area[3]),
|
||||
radius=20,
|
||||
|
@ -323,12 +323,10 @@ def generate_default_profile(
|
|||
bar_height = 25
|
||||
bar_y = stats_area[3] - 60
|
||||
|
||||
# Enhance the level bar with a modern design
|
||||
# Create progress bar background
|
||||
bar_bg = Image.new("RGBA", (bar_width, bar_height), (0, 0, 0, 100))
|
||||
bar_progress = Image.new("RGBA", (
|
||||
int(bar_width * (current_xp - previous_xp) / (next_xp - previous_xp)),
|
||||
bar_height
|
||||
), level_bar_color + (200,)) # Add alpha channel
|
||||
progress_width = max(1, int(bar_width * progress)) # Ensure at least 1 pixel width
|
||||
bar_progress = Image.new("RGBA", (progress_width, bar_height), level_bar_color + (200,))
|
||||
|
||||
# Add gradient to progress bar
|
||||
gradient = Image.new("RGBA", bar_progress.size, (0, 0, 0, 0))
|
||||
|
@ -346,8 +344,15 @@ def generate_default_profile(
|
|||
bar_mask_draw = ImageDraw.Draw(bar_mask)
|
||||
bar_mask_draw.rounded_rectangle((0, 0, bar_width-1, bar_height-1), radius=bar_height//2, fill=255)
|
||||
|
||||
# Apply mask to background and progress bar
|
||||
bar_bg.putalpha(bar_mask)
|
||||
bar_progress.putalpha(bar_mask)
|
||||
bar_progress_masked = Image.new("RGBA", (bar_width, bar_height), (0, 0, 0, 0))
|
||||
bar_progress_masked.paste(bar_progress, (0, 0))
|
||||
bar_progress_masked.putalpha(bar_mask)
|
||||
|
||||
# Paste progress bar onto stats layer
|
||||
stats_layer.paste(bar_bg, (start_x, bar_y), bar_bg)
|
||||
stats_layer.paste(bar_progress_masked, (start_x, bar_y), bar_progress_masked)
|
||||
|
||||
# XP text
|
||||
xp_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 24)
|
||||
|
@ -383,20 +388,24 @@ def generate_default_profile(
|
|||
pfp_x = 40
|
||||
pfp_y = (card.height - pfp_size[1]) // 2
|
||||
|
||||
# Create a new image for final composition
|
||||
final_image = Image.new("RGBA", desired_card_size, (0, 0, 0, 0))
|
||||
|
||||
# Add blur effect if enabled
|
||||
if blur:
|
||||
blur_section = imgtools.blur_section(card, (stats_area[0], 0, card.width, card.height))
|
||||
card.paste(blur_section, (stats_area[0], 0), blur_section)
|
||||
|
||||
# Paste the layers
|
||||
card.paste(stats_layer, (0, 0), stats_layer)
|
||||
card.paste(pfp, (pfp_x, pfp_y), pfp)
|
||||
# Paste layers in correct order
|
||||
final_image.paste(card, (0, 0), card)
|
||||
final_image.paste(stats_layer, (0, 0), stats_layer)
|
||||
final_image.paste(pfp, (pfp_x, pfp_y), pfp)
|
||||
|
||||
if debug:
|
||||
card.show()
|
||||
final_image.show()
|
||||
buffer = BytesIO()
|
||||
card.save(buffer, format="WEBP")
|
||||
card.close()
|
||||
final_image.save(buffer, format="WEBP", quality=95)
|
||||
final_image.close()
|
||||
return buffer.getvalue(), False
|
||||
|
||||
if pfp_animated and not bg_animated:
|
||||
|
|
Loading…
Add table
Reference in a new issue