Enhance glass effect implementation in imgtools.py and default.py. Ensure images are in RGBA mode before applying effects, and update the glass effect application in the stats layer to use the glass background as a mask for improved visual consistency.
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run

This commit is contained in:
Valerie 2025-05-24 07:25:02 -04:00
parent d5e3a00996
commit 06025296bb
2 changed files with 12 additions and 6 deletions

View file

@ -390,17 +390,21 @@ def get_avg_duration(image: Image.Image) -> int:
def create_glass_effect(image: Image.Image, opacity: float = 0.3, blur_radius: int = 10) -> Image.Image:
"""Create a modern glass effect with blur and transparency."""
# Create a copy of the image to blur
# Create a copy of the image and ensure it's in RGBA mode
glass = image.copy()
if glass.mode != "RGBA":
glass = glass.convert("RGBA")
# Apply gaussian blur
glass = glass.filter(ImageFilter.GaussianBlur(blur_radius))
# Apply gaussian blur (must be in RGB mode for blur)
glass_rgb = glass.convert("RGB")
glass_rgb = glass_rgb.filter(ImageFilter.GaussianBlur(blur_radius))
glass = glass_rgb.convert("RGBA")
# Create a semi-transparent white overlay
overlay = Image.new('RGBA', image.size, (255, 255, 255, int(255 * opacity)))
# Composite the blurred image with the overlay
glass = Image.alpha_composite(glass.convert('RGBA'), overlay)
glass = Image.alpha_composite(glass, overlay)
return glass

View file

@ -250,13 +250,15 @@ def generate_default_profile(
# Create glass effect for stats area
stats_bg = card.crop(stats_area)
if stats_bg.mode != "RGBA":
stats_bg = stats_bg.convert("RGBA")
glass_bg = imgtools.create_glass_effect(stats_bg, opacity=0.3, blur_radius=20)
stats_layer.paste(glass_bg, stats_area)
stats_layer.paste(glass_bg, stats_area, glass_bg) # Use glass_bg as mask
# Add rounded corners to the glass effect
stats_mask = imgtools.get_rounded_corner_mask(glass_bg, radius=30)
glass_bg.putalpha(stats_mask)
stats_layer.paste(glass_bg, stats_area, glass_bg)
stats_layer.paste(glass_bg, stats_area, glass_bg) # Use glass_bg as mask again
# Draw stats with improved styling
draw = ImageDraw.Draw(stats_layer)