"""Generate a clean OG image (1200x630, white background, centered logo).""" from PIL import Image import os ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) LOGO = os.path.join(ROOT, "public/images/logo/dealplustech-logo.png") OUT = os.path.join(ROOT, "public/images/og/default-og.jpg") CANVAS_W, CANVAS_H = 1200, 630 LOGO_MAX_W = int(CANVAS_W * 0.70) # 70% of canvas width LOGO_MAX_H = int(CANVAS_H * 0.70) # 70% of canvas height # 1. White canvas canvas = Image.new("RGB", (CANVAS_W, CANVAS_H), (255, 255, 255)) # 2. Open logo (RGBA) logo = Image.open(LOGO).convert("RGBA") lw, lh = logo.size print(f"logo original: {lw}x{lh}") # 3. Scale logo to fit within 70% box, preserve aspect ratio scale = min(LOGO_MAX_W / lw, LOGO_MAX_H / lh) new_w = int(lw * scale) new_h = int(lh * scale) logo = logo.resize((new_w, new_h), Image.LANCZOS) print(f"logo scaled: {new_w}x{new_h}") # 4. Center x0 = (CANVAS_W - new_w) // 2 y0 = (CANVAS_H - new_h) // 2 # 5. Paste (uses alpha as mask) canvas.paste(logo, (x0, y0), logo) # 6. Save as JPEG quality 90 os.makedirs(os.path.dirname(OUT), exist_ok=True) canvas.save(OUT, "JPEG", quality=90, optimize=True, progressive=True) size = os.path.getsize(OUT) print(f"wrote: {OUT} ({size:,} bytes)")