fix(nhl): Use 4-tuple box and alpha mask Image for Image.paste() compatibility

This commit is contained in:
ChuckBuilds
2025-04-17 13:44:23 -05:00
parent cf6685e3d2
commit 827f07b836

View File

@@ -327,10 +327,13 @@ def create_scorebug_image(game_details):
away_logo = Image.open(game_details["away_logo_path"]).convert("RGBA")
away_logo.thumbnail(logo_size, Image.Resampling.LANCZOS)
away_mask = away_logo.split()[-1] # Extract alpha channel as mask
# Calculate top-left corner
pos_x = away_logo_pos[0]
pos_y = (DISPLAY_HEIGHT - away_logo.height) // 2
img.paste(away_logo, (pos_x, pos_y), away_mask) # Use 2-tuple pos and image mask
# Calculate 4-element box explicitly
left = away_logo_pos[0]
upper = (DISPLAY_HEIGHT - away_logo.height) // 2
right = left + away_logo.width
lower = upper + away_logo.height
box = (left, upper, right, lower)
img.paste(away_logo, box, away_mask) # Use 4-tuple box and image mask
except Exception as e:
logging.error(f"Error loading/pasting away logo {game_details['away_logo_path']}: {e}")
# Draw placeholder text if logo fails
@@ -347,10 +350,13 @@ def create_scorebug_image(game_details):
home_logo = Image.open(game_details["home_logo_path"]).convert("RGBA")
home_logo.thumbnail(logo_size, Image.Resampling.LANCZOS)
home_mask = home_logo.split()[-1] # Extract alpha channel as mask
# Calculate top-left corner
pos_x = home_logo_pos[0]
pos_y = (DISPLAY_HEIGHT - home_logo.height) // 2
img.paste(home_logo, (pos_x, pos_y), home_mask) # Use 2-tuple pos and image mask
# Calculate 4-element box explicitly
left = home_logo_pos[0]
upper = (DISPLAY_HEIGHT - home_logo.height) // 2
right = left + home_logo.width
lower = upper + home_logo.height
box = (left, upper, right, lower)
img.paste(home_logo, box, home_mask) # Use 4-tuple box and image mask
except Exception as e:
logging.error(f"Error loading/pasting home logo {game_details['home_logo_path']}: {e}")
draw.text(home_logo_pos, game_details["home_abbr"], font=team_font, fill="white")
@@ -1064,10 +1070,13 @@ class NHLScoreboardManager:
away_logo = Image.open(game_details["away_logo_path"]).convert("RGBA")
away_logo.thumbnail(logo_size, Image.Resampling.LANCZOS)
away_mask = away_logo.split()[-1] # Extract alpha channel as mask
# Calculate top-left corner
pos_x = away_logo_x
pos_y = (self.display_height - away_logo.height) // 2
img.paste(away_logo, (pos_x, pos_y), away_mask) # Use 2-tuple pos and image mask
# Calculate 4-element box explicitly
left = away_logo_x
upper = (self.display_height - away_logo.height) // 2
right = left + away_logo.width
lower = upper + away_logo.height
box = (left, upper, right, lower)
img.paste(away_logo, box, away_mask) # Use 4-tuple box and image mask
except Exception as e:
logging.error(f"[NHL] Error rendering upcoming away logo {game_details['away_logo_path']}: {e}")
draw.text((away_logo_x, 5), game_details.get("away_abbr", "?"), font=font_team, fill="white")
@@ -1080,10 +1089,13 @@ class NHLScoreboardManager:
home_logo = Image.open(game_details["home_logo_path"]).convert("RGBA")
home_logo.thumbnail(logo_size, Image.Resampling.LANCZOS)
home_mask = home_logo.split()[-1] # Extract alpha channel as mask
# Calculate top-left corner
pos_x = home_logo_x
pos_y = (self.display_height - home_logo.height) // 2
img.paste(home_logo, (pos_x, pos_y), home_mask) # Use 2-tuple pos and image mask
# Calculate 4-element box explicitly
left = home_logo_x
upper = (self.display_height - home_logo.height) // 2
right = left + home_logo.width
lower = upper + home_logo.height
box = (left, upper, right, lower)
img.paste(home_logo, box, home_mask) # Use 4-tuple box and image mask
except Exception as e:
logging.error(f"[NHL] Error rendering upcoming home logo {game_details['home_logo_path']}: {e}")
draw.text((home_logo_x, 5), game_details.get("home_abbr", "?"), font=font_team, fill="white")
@@ -1157,10 +1169,13 @@ class NHLScoreboardManager:
away_logo.thumbnail(logo_size, Image.Resampling.LANCZOS)
away_logo_drawn_size = away_logo.size # Keep track of size
away_mask = away_logo.split()[-1] # Extract alpha channel as mask
# Calculate top-left corner
pos_x = away_logo_x
pos_y = (self.display_height - away_logo.height) // 2
img.paste(away_logo, (pos_x, pos_y), away_mask) # Use 2-tuple pos and image mask
# Calculate 4-element box explicitly
left = away_logo_x
upper = (self.display_height - away_logo.height) // 2
right = left + away_logo.width
lower = upper + away_logo.height
box = (left, upper, right, lower)
img.paste(away_logo, box, away_mask) # Use 4-tuple box and image mask
except Exception as e:
logging.error(f"[NHL] Error rendering away logo {game_details['away_logo_path']}: {e}")
draw.text((away_logo_x + 2, 5), game_details.get("away_abbr", "?"), font=font_team, fill="white")
@@ -1178,10 +1193,13 @@ class NHLScoreboardManager:
home_logo.thumbnail(logo_size, Image.Resampling.LANCZOS)
home_logo_drawn_size = home_logo.size # Keep track of size
home_mask = home_logo.split()[-1] # Extract alpha channel as mask
# Calculate top-left corner
pos_x = home_logo_x
pos_y = (self.display_height - home_logo.height) // 2
img.paste(home_logo, (pos_x, pos_y), home_mask) # Use 2-tuple pos and image mask
# Calculate 4-element box explicitly
left = home_logo_x
upper = (self.display_height - home_logo.height) // 2
right = left + home_logo.width
lower = upper + home_logo.height
box = (left, upper, right, lower)
img.paste(home_logo, box, home_mask) # Use 4-tuple box and image mask
except Exception as e:
logging.error(f"[NHL] Error rendering home logo {game_details['home_logo_path']}: {e}")
draw.text((home_logo_x + 2, 5), game_details.get("home_abbr", "?"), font=font_team, fill="white")