mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
1px black outline on text in sports displays
This commit is contained in:
@@ -66,6 +66,27 @@ class BaseNCAABaseballManager:
|
||||
logger.error(f"[NCAABaseball] Error loading logo for team {team_abbr}: {e}")
|
||||
return None
|
||||
|
||||
def _draw_text_with_outline(self, draw, text, position, font, fill=(255, 255, 255), outline_color=(0, 0, 0)):
|
||||
"""
|
||||
Draw text with a black outline for better readability.
|
||||
|
||||
Args:
|
||||
draw: ImageDraw object
|
||||
text: Text to draw
|
||||
position: (x, y) position to draw the text
|
||||
font: Font to use
|
||||
fill: Text color (default: white)
|
||||
outline_color: Outline color (default: black)
|
||||
"""
|
||||
x, y = position
|
||||
|
||||
# Draw the outline by drawing the text in black at 8 positions around the text
|
||||
for dx, dy in [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]:
|
||||
draw.text((x + dx, y + dy), text, font=font, fill=outline_color)
|
||||
|
||||
# Draw the text in the specified color
|
||||
draw.text((x, y), text, font=font, fill=fill)
|
||||
|
||||
def _draw_base_indicators(self, draw: ImageDraw.Draw, bases_occupied: List[bool], center_x: int, y: int) -> None:
|
||||
"""Draw base indicators on the display."""
|
||||
base_size = 8
|
||||
@@ -120,7 +141,8 @@ class BaseNCAABaseballManager:
|
||||
status_x = (width - status_width) // 2
|
||||
status_y = 2
|
||||
self.display_manager.draw = draw
|
||||
self.display_manager._draw_bdf_text(status_text, status_x, status_y, color=(255, 255, 255), font=self.display_manager.calendar_font)
|
||||
status_font = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6) # Using a default small font
|
||||
self._draw_text_with_outline(draw, status_text, (status_x, status_y), status_font)
|
||||
|
||||
game_time = datetime.fromisoformat(game_data['start_time'].replace('Z', '+00:00'))
|
||||
timezone_str = self.config.get('timezone', 'UTC')
|
||||
@@ -140,23 +162,23 @@ class BaseNCAABaseballManager:
|
||||
|
||||
date_width = draw.textlength(game_date, font=date_font)
|
||||
date_x = (width - date_width) // 2
|
||||
date_y = (height - date_font.size) // 2 - 3
|
||||
draw.text((date_x, date_y), game_date, font=date_font, fill=(255, 255, 255))
|
||||
date_y = (height - date_font.getmetrics()[0]) // 2 - 3 # Adjusted for font metrics
|
||||
self._draw_text_with_outline(draw, game_date, (date_x, date_y), date_font)
|
||||
|
||||
time_width = draw.textlength(game_time_str, font=time_font)
|
||||
time_x = (width - time_width) // 2
|
||||
time_y = date_y + 10
|
||||
draw.text((time_x, time_y), game_time_str, font=time_font, fill=(255, 255, 255))
|
||||
self._draw_text_with_outline(draw, game_time_str, (time_x, time_y), time_font)
|
||||
|
||||
# For recent/final games, show scores and status
|
||||
elif game_data['status'] in ['status_final', 'final', 'completed']:
|
||||
status_text = "Final"
|
||||
self.display_manager.calendar_font.set_char_size(height=7*64)
|
||||
status_width = self.display_manager.get_text_width(status_text, self.display_manager.calendar_font)
|
||||
status_font = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6) # Using a default small font
|
||||
status_width = draw.textlength(status_text, font=status_font)
|
||||
status_x = (width - status_width) // 2
|
||||
status_y = 2
|
||||
self.display_manager.draw = draw
|
||||
self.display_manager._draw_bdf_text(status_text, status_x, status_y, color=(255, 255, 255), font=self.display_manager.calendar_font)
|
||||
self._draw_text_with_outline(draw, status_text, (status_x, status_y), status_font)
|
||||
|
||||
away_score = str(game_data['away_score'])
|
||||
home_score = str(game_data['home_score'])
|
||||
@@ -165,8 +187,8 @@ class BaseNCAABaseballManager:
|
||||
|
||||
score_width = draw.textlength(score_text, font=score_font)
|
||||
score_x = (width - score_width) // 2
|
||||
score_y = height - score_font.size - 2
|
||||
draw.text((score_x, score_y), score_text, font=score_font, fill=(255, 255, 255))
|
||||
score_y = height - score_font.getmetrics()[0] - 2 # Adjusted for font metrics
|
||||
self._draw_text_with_outline(draw, score_text, (score_x, score_y), score_font)
|
||||
|
||||
return image
|
||||
|
||||
@@ -494,7 +516,7 @@ class NCAABaseballLiveManager(BaseNCAABaseballManager):
|
||||
inning_width = inning_bbox[2] - inning_bbox[0]
|
||||
inning_x = (width - inning_width) // 2
|
||||
inning_y = 0
|
||||
draw.text((inning_x, inning_y), inning_text, fill=(255, 255, 255), font=self.display_manager.font)
|
||||
self._draw_text_with_outline(draw, inning_text, (inning_x, inning_y), self.display_manager.font)
|
||||
|
||||
bases_occupied = game_data['bases_occupied']
|
||||
outs = game_data.get('outs', 0)
|
||||
@@ -555,13 +577,11 @@ class NCAABaseballLiveManager(BaseNCAABaseballManager):
|
||||
count_y = cluster_bottom_y + 2
|
||||
count_x = bases_origin_x + (base_cluster_width - count_text_width) // 2
|
||||
self.display_manager.draw = draw
|
||||
self.display_manager._draw_bdf_text(count_text, count_x, count_y, text_color, font=bdf_font)
|
||||
self._draw_text_with_outline(draw, count_text, (count_x, count_y), bdf_font, fill=text_color)
|
||||
|
||||
score_font = self.display_manager.font; outline_color = (0, 0, 0); score_text_color = (255, 255, 255)
|
||||
def draw_bottom_outlined_text(x, y, text):
|
||||
draw.text((x-1, y), text, font=score_font, fill=outline_color); draw.text((x+1, y), text, font=score_font, fill=outline_color)
|
||||
draw.text((x, y-1), text, font=score_font, fill=outline_color); draw.text((x, y+1), text, font=score_font, fill=outline_color)
|
||||
draw.text((x, y), text, font=score_font, fill=score_text_color)
|
||||
self._draw_text_with_outline(draw, text, (x,y), score_font, fill=score_text_color, outline_color=outline_color)
|
||||
away_abbr = game_data['away_team']; home_abbr = game_data['home_team']
|
||||
away_score_str = str(game_data['away_score']); home_score_str = str(game_data['home_score'])
|
||||
away_text = f"{away_abbr}:{away_score_str}"; home_text = f"{home_abbr}:{home_score_str}"
|
||||
|
||||
Reference in New Issue
Block a user