fix image loading
This commit is contained in:
+18
-14
@@ -20,22 +20,26 @@ class ScoreboardMatrix():
|
|||||||
matrix = RGBMatrix(options=options)
|
matrix = RGBMatrix(options=options)
|
||||||
canvas = matrix.CreateFrameCanvas()
|
canvas = matrix.CreateFrameCanvas()
|
||||||
|
|
||||||
def load_logo_to_image(self, league, abbr, width, height, x_offset, y_offset):
|
def load_logo(self, league, abbr):
|
||||||
key = f"{league}_{abbr}.png"
|
key = f"{league}_{abbr}"
|
||||||
logo_path = os.path.join(vars.LOGOS_DIR, key)
|
if key in self.logo_cache:
|
||||||
if not os.path.exists(logo_path):
|
return self.logo_cache[key]
|
||||||
|
|
||||||
|
path = os.path.join(vars.LOGO_DIR, f"{key}.png")
|
||||||
|
if not os.path.exists(path):
|
||||||
|
print(f"Logo not found: {path}")
|
||||||
|
self.logo_cache[key] = None
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if key in self.logo_cache:
|
try:
|
||||||
loaded_image = self.logo_cache[key]
|
# FIX: convert to RGB here so draw_logo always gets 3-channel pixels
|
||||||
else:
|
img = Image.open(path).convert("RGB")
|
||||||
loaded_image = Image.open(logo_path).convert("RGB")
|
self.logo_cache[key] = img
|
||||||
self.logo_cache[key] = loaded_image
|
return img
|
||||||
|
except Exception as e:
|
||||||
image = Image.new("RGB", (width, height), (0,0,0))
|
print(f"Error loading logo {key}: {e}")
|
||||||
image.paste(loaded_image.resize((width, height), (x_offset, y_offset)))
|
self.logo_cache[key] = None
|
||||||
|
return None
|
||||||
return image
|
|
||||||
|
|
||||||
def iterate_slide_count(self):
|
def iterate_slide_count(self):
|
||||||
self.slide_count += 1
|
self.slide_count += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user