from __future__ import annotations import sys from pathlib import Path from PIL import Image def build_square_ico(src: Path, dst: Path) -> None: im = Image.open(src).convert("RGBA") w, h = im.size s = max(w, h) square = Image.new("RGBA", (s, s), (0, 0, 0, 0)) square.paste(im, ((s - w) // 2, (s - h) // 2)) square = square.resize((256, 256), Image.LANCZOS) # A single 256x256 icon is sufficient for modern Windows; smaller sizes # will be auto-derived by the shell if needed. square.save(dst, format="ICO") def main(argv: list[str]) -> int: if len(argv) != 3: print("Usage: python make_icon.py ", file=sys.stderr) return 2 src = Path(argv[1]).resolve() dst = Path(argv[2]).resolve() if not src.exists(): print(f"Icon source not found: {src}", file=sys.stderr) return 2 build_square_ico(src, dst) print(f"Wrote: {dst}") return 0 if __name__ == "__main__": raise SystemExit(main(sys.argv))