Enhance profile card generation in default.py by setting default colors to ruby red, improving the stats area with a modern glass effect, and refining the level bar design with gradients and rounded corners for a more visually appealing layout.
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run

This commit is contained in:
Valerie 2025-05-25 21:24:04 -04:00
parent fc0b4341d6
commit 6d9ac89123
2 changed files with 78 additions and 37 deletions

View file

@ -146,9 +146,9 @@ def generate_default_profile(
Returns:
t.Tuple[bytes, bool]: The generated full profile image as bytes, and whether the image is animated.
"""
user_color = user_color or base_color
stat_color = stat_color or base_color
level_bar_color = level_bar_color or base_color
user_color = user_color or (155, 17, 30) # Default to ruby red
stat_color = stat_color or (155, 17, 30) # Default to ruby red
level_bar_color = level_bar_color or (155, 17, 30) # Default to ruby red
if isinstance(background_bytes, str) and background_bytes.startswith("http"):
log.debug("Background image is a URL, attempting to download")
@ -240,7 +240,7 @@ def generate_default_profile(
# Create the stats layer with glass effect
stats_layer = Image.new("RGBA", desired_card_size, (0, 0, 0, 0))
# Define the stats area (right side of the card)
# Define the stats area with a modern glass effect
stats_area = (
400, # x1 - Start after profile picture
20, # y1 - Start near top
@ -248,16 +248,34 @@ def generate_default_profile(
430 # y2 - End near bottom
)
# 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.25, blur_radius=15)
# 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))
# Add rounded corners to the glass effect
stats_mask = imgtools.get_rounded_corner_mask(glass_bg, radius=20)
glass_bg.putalpha(stats_mask)
stats_layer.paste(glass_bg, stats_area, glass_bg)
# 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))
gradient_draw.rounded_rectangle(
(stats_area[0], stats_area[1]+i, stats_area[2], stats_area[3]),
radius=20,
fill=(255, 255, 255, opacity)
)
# Composite the glass effect
stats_layer = Image.alpha_composite(stats_layer, glass)
stats_layer = Image.alpha_composite(stats_layer, gradient)
# Add a subtle border
border_draw = ImageDraw.Draw(stats_layer)
border_draw.rounded_rectangle(
stats_area,
radius=20,
outline=(255, 255, 255, 100),
width=2
)
# Draw stats with improved styling
draw = ImageDraw.Draw(stats_layer)
@ -305,14 +323,31 @@ def generate_default_profile(
bar_height = 25
bar_y = stats_area[3] - 60
progress_bar = imgtools.make_progress_bar(
bar_width,
bar_height,
progress,
color=level_bar_color,
background_color=(100, 100, 100, 160)
)
stats_layer.paste(progress_bar, (start_x, bar_y), progress_bar)
# Enhance the level bar with a modern design
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
# Add gradient to progress bar
gradient = Image.new("RGBA", bar_progress.size, (0, 0, 0, 0))
gradient_draw = ImageDraw.Draw(gradient)
for i in range(bar_height):
opacity = int(100 * (1 - i/bar_height))
gradient_draw.rectangle(
(0, i, bar_progress.width, i+1),
fill=(255, 255, 255, opacity)
)
bar_progress = Image.alpha_composite(bar_progress, gradient)
# Round the corners
bar_mask = Image.new("L", (bar_width, bar_height))
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)
bar_bg.putalpha(bar_mask)
bar_progress.putalpha(bar_mask)
# XP text
xp_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 24)

View file

@ -165,27 +165,31 @@ class ProfileFormatting(MixinMeta):
pdata = conf.prestigedata[profile.prestige]
if conf.use_embeds or self.db.force_embeds:
txt = f"{level}" + _("Level {}\n").format(humanize_number(profile.level))
if pdata:
txt += f"{trophy}" + _("Prestige {}\n").format(
f"{humanize_number(profile.prestige)} {pdata.emoji_string}"
)
txt += f"{star}{humanize_number(profile.stars)}" + _(" stars\n")
txt += f"{chat}{humanize_number(profile.messages)}" + _(" messages sent\n")
txt += f"{mic}{utils.humanize_delta(profile.voice)}" + _(" in voice\n")
progress_txt = f"{bulb}{humanize_number(progress)}/{humanize_number(current_diff)}"
txt += progress_txt + _(" Exp ({} total)\n").format(humanize_number(current_xp))
if conf.showbal:
balance = await bank.get_balance(member)
creditname = await bank.get_currency_name(guild)
txt += f"{money}{humanize_number(balance)} {creditname}\n"
color = member.color
if profile.statcolor:
color = discord.Color.from_rgb(*utils.string_to_rgb(profile.statcolor))
elif profile.barcolor:
color = discord.Color.from_rgb(*utils.string_to_rgb(profile.barcolor))
elif profile.namecolor:
color = discord.Color.from_rgb(*utils.string_to_rgb(profile.namecolor))
else:
# Default to ruby color if no custom color is set
color = discord.Color.from_rgb(155, 17, 30) # Ruby red
# Create a cleaner layout with emojis and values aligned
txt = ""
txt += f"{level} **Level {humanize_number(profile.level)}**\n"
if pdata:
txt += f"{trophy} **Prestige {humanize_number(profile.prestige)}** {pdata.emoji_string}\n"
txt += f"{star} **{humanize_number(profile.stars)}** stars\n"
txt += f"{chat} **{humanize_number(profile.messages)}** messages sent\n"
txt += f"{mic} **{utils.humanize_delta(profile.voice)}** in voice\n"
progress_txt = f"{bulb} **{humanize_number(progress)}/{humanize_number(current_diff)}**"
txt += f"{progress_txt} XP (**{humanize_number(current_xp)}** total)\n"
if conf.showbal:
balance = await bank.get_balance(member)
creditname = await bank.get_currency_name(guild)
txt += f"{money} **{humanize_number(balance)}** {creditname}\n"
embed = discord.Embed(description=txt, color=color)
embed.set_author(
name=_("{}'s Profile").format(member.display_name if profile.show_displayname else member.name),
@ -197,7 +201,9 @@ class ProfileFormatting(MixinMeta):
),
icon_url=guild.icon,
)
embed.add_field(name=_("Progress"), value=box(bar, lang="python"), inline=False)
# Make the progress bar more visually appealing
bar = box(bar.replace("", "").replace("", ""), lang="")
embed.add_field(name=_("Level Progress"), value=bar, inline=False)
return embed
kwargs = {