"""Generate /public/og.png — a 1200x630 Open Graph image for Diesel Depot. Brand-styled card with the logo on the left, big name + tagline on the right. Used for WhatsApp / Twitter / Facebook link previews of depot.apphub.co.za. """ from PIL import Image, ImageDraw, ImageFont import os OUT = os.path.join(os.path.dirname(__file__), "..", "Volumes/EXT/DEVELOPMENT/MINIMAX/DIESEL_DEPOT/public/og.png") OUT = "/Volumes/EXT/DEVELOPMENT/MINIMAX/DIESEL_DEPOT/public/og.png" LOGO = "/Volumes/EXT/DEVELOPMENT/MINIMAX/DIESEL_DEPOT/public/logo.png" # Brand colours — keep aligned with the CSS theme. PRIMARY = (26, 122, 82) # #1a7a52 (manifest theme-color) PRIMARY_DARK = (20, 96, 64) ACCENT = (255, 255, 255) MUTED = (210, 235, 220) W, H = 1200, 630 img = Image.new("RGB", (W, H), PRIMARY) d = ImageDraw.Draw(img) # Subtle diagonal gradient (primary → primary_dark) for depth. PIL doesn't # do real gradients natively, so fake one with a few horizontal bands. for y in range(H): t = y / H r = int(PRIMARY[0] * (1 - t) + PRIMARY_DARK[0] * t) g = int(PRIMARY[1] * (1 - t) + PRIMARY_DARK[1] * t) b = int(PRIMARY[2] * (1 - t) + PRIMARY_DARK[2] * t) d.line([(0, y), (W, y)], fill=(r, g, b)) # Fonts — prefer Helvetica for a clean sans, fall back to PIL default. def load_font(size, bold=False): candidates = [ "/System/Library/Fonts/Helvetica.ttc", "/Library/Fonts/Arial Unicode.ttf", ] for c in candidates: if os.path.exists(c): try: return ImageFont.truetype(c, size, index=1 if bold else 0) except Exception: continue return ImageFont.load_default() f_title = load_font(96, bold=True) f_sub = load_font(36) f_foot = load_font(26) # Logo on the left, vertically centred. Resize to a target height. logo = Image.open(LOGO).convert("RGBA") target_h = 340 ratio = target_h / logo.height logo = logo.resize((int(logo.width * ratio), target_h), Image.LANCZOS) logo_x = 80 logo_y = (H - logo.height) // 2 img.paste(logo, (logo_x, logo_y), logo) # Title — "Diesel Depot" text_x = logo_x + logo.width + 60 title = "Diesel Depot" bbox = d.textbbox((0, 0), title, font=f_title) title_w = bbox[2] - bbox[0] # If still too wide, shrink to fit if text_x + title_w > W - 60: f_title = load_font(80, bold=True) bbox = d.textbbox((0, 0), title, font=f_title) title_w = bbox[2] - bbox[0] d.text((text_x, 210), title, font=f_title, fill=ACCENT) # Tagline tag = "Depot & fleet management" bbox = d.textbbox((0, 0), tag, font=f_sub) d.text((text_x, 350), tag, font=f_sub, fill=MUTED) # Bottom line foot = "depot.apphub.co.za" d.text((60, H - 60), foot, font=f_foot, fill=MUTED) # A small "fuel drop" accent in the bottom-right corner (matches the logo) d.polygon([(W - 90, H - 30), (W - 60, H - 60), (W - 30, H - 30)], fill=(232, 160, 42)) # amber accent img.save(OUT, "PNG", optimize=True) print(f"Wrote {OUT} ({os.path.getsize(OUT)} bytes)")