#!/usr/bin/env python3 """Generates the base Tauri icon from the official project logo. The official logo is `logo.png` in the repository root (RGBA, transparent background, suitable for both light and dark themes). It is not modified here. Output: apps/gui/src-tauri/icons/source.png 1024 px artwork centered over a rounded dark background; CI and `npx @tauri-apps/cli icon` derive all remaining icon formats from it. Usage: python3 scripts/generate-logo.py """ import os from PIL import Image, ImageDraw ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") ICONS_DIR = os.path.join(ROOT, "apps/gui/src-tauri/icons") ICON_BG = (10, 16, 28) # dark navy background matching the original artwork def crop_square(im, margin=0.04): """Crops to visible pixels (opacity > 16, ignoring faint artifacts) and centers in a square.""" box = im.getchannel("A").point(lambda v: 255 if v > 16 else 0).getbbox() im = im.crop(box) w, h = im.size side = round(max(w, h) * (1 + 2 * margin)) canvas = Image.new("RGBA", (side, side), (0, 0, 0, 0)) canvas.paste(im, ((side - w) // 2, (side - h) // 2), im) return canvas def main(): logo = crop_square(Image.open(os.path.join(ROOT, "logo.png")).convert("RGBA")) side = 1024 bg = Image.new("RGBA", (side, side), ICON_BG + (255,)) art = logo.resize((round(side * 0.82),) * 2, Image.LANCZOS) bg.paste(art, ((side - art.width) // 2, (side - art.height) // 2), art) mask = Image.new("L", (side, side), 0) ImageDraw.Draw(mask).rounded_rectangle((0, 0, side - 1, side - 1), radius=round(side * 0.2237), fill=255) icon = Image.new("RGBA", (side, side), (0, 0, 0, 0)) icon.paste(bg, (0, 0), mask) os.makedirs(ICONS_DIR, exist_ok=True) dest = os.path.join(ICONS_DIR, "source.png") icon.save(dest, optimize=True) os.chmod(dest, 0o644) print("icons/source.png") if __name__ == "__main__": main()