From 6f4a735bee6d74e4d1b98b3170974487ea2267a0 Mon Sep 17 00:00:00 2001 From: ChuckBuilds <33324927+ChuckBuilds@users.noreply.github.com> Date: Fri, 18 Apr 2025 11:35:55 -0500 Subject: [PATCH] Fix NHL logo display by using separate images and alpha compositing - Create separate images for each logo - Use alpha_composite to properly combine images - Preserve transparency during image combination --- src/nhl_managers.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/nhl_managers.py b/src/nhl_managers.py index 4c9973b9..151089a9 100644 --- a/src/nhl_managers.py +++ b/src/nhl_managers.py @@ -224,19 +224,23 @@ class BaseNHLManager: def _draw_scorebug_layout(self): """Draw the scorebug layout for the current game.""" try: - # Create a new black image - img = Image.new('RGB', (self.display_width, self.display_height), 'black') - draw = ImageDraw.Draw(img) + # Create a new black image for the main display + main_img = Image.new('RGB', (self.display_width, self.display_height), 'black') + draw = ImageDraw.Draw(main_img) # Load logos once home_logo = self._load_and_resize_logo(self.current_game["home_abbr"]) away_logo = self._load_and_resize_logo(self.current_game["away_abbr"]) + # Create separate images for each logo + home_img = Image.new('RGB', (self.display_width, self.display_height), 'black') + away_img = Image.new('RGB', (self.display_width, self.display_height), 'black') + # Draw home team logo (right side) if home_logo: home_x = 3 * self.display_width // 4 - home_logo.width // 2 home_y = self.display_height // 4 - home_logo.height // 2 - img.paste(home_logo, (home_x, home_y), home_logo) + home_img.paste(home_logo, (home_x, home_y), home_logo) else: self.logger.warning(f"Home logo is None for team {self.current_game['home_abbr']}") @@ -244,10 +248,15 @@ class BaseNHLManager: if away_logo: away_x = self.display_width // 4 - away_logo.width // 2 away_y = self.display_height // 4 - away_logo.height // 2 - img.paste(away_logo, (away_x, away_y), away_logo) + away_img.paste(away_logo, (away_x, away_y), away_logo) else: self.logger.warning(f"Away logo is None for team {self.current_game['away_abbr']}") + # Combine the images + main_img = Image.alpha_composite(main_img.convert('RGBA'), home_img.convert('RGBA')) + main_img = Image.alpha_composite(main_img, away_img.convert('RGBA')) + main_img = main_img.convert('RGB') + # Draw scores in the format "AWAY - HOME" home_score = str(self.current_game["home_score"]) away_score = str(self.current_game["away_score"]) @@ -261,6 +270,7 @@ class BaseNHLManager: score_y = 3 * self.display_height // 4 - 10 # Draw the score text + draw = ImageDraw.Draw(main_img) draw.text((score_x, score_y), score_text, font=self.fonts['score'], fill=(255, 255, 255)) # Draw game status (period and time or "FINAL") @@ -272,7 +282,7 @@ class BaseNHLManager: draw.text((status_x, status_y), status_text, font=self.fonts['status'], fill=(255, 255, 255)) # Display the image - self.display_manager.image.paste(img, (0, 0)) + self.display_manager.image.paste(main_img, (0, 0)) self.display_manager.update_display() except Exception as e: