import os from pathlib import Path from PIL import Image logo_cache = {} SCRIPT_DIR = Path(__file__).parent.resolve() ASSET_DIR = os.path.join(SCRIPT_DIR, "../assets") LOGO_DIR = os.path.join(ASSET_DIR, "logos") def draw_pil_image(canvas, img): for x in range(img.width): for y in range(img.height): r, g, b = img.getpixel((x, y)) canvas.SetPixel(x, y, b, g, r) # bgr panels def load_logo(league, abbr): key = f"{league}_{abbr}" if key in logo_cache: return logo_cache[key] path = os.path.join(LOGO_DIR, f"{key}.png") if not os.path.exists(path): print(f"Logo not found: {path}") logo_cache[key] = None return None try: img = Image.open(path).convert("RGB") logo_cache[key] = img return img except Exception as e: print(f"Error loading logo {key}: {e}") logo_cache[key] = None return None def draw_logo(canvas, img, x, y): if img is None: return for px in range(img.width): for py in range(img.height): r, g, b = img.getpixel((px, py)) canvas.SetPixel(x + px, y + py, r, b, g) # bgr panels