Files

46 lines
1.5 KiB
Python

"""One-time icon generator (run by a developer, not by the build).
Source art: docs/samples/icon.png (azure pinwheel, ~1032x967, transparent).
Produces two committed assets:
- packaging/icon.ico multi-size, for the exe + installer
- cim_suite/shell/resources/app_icon.png 256x256, for the runtime Qt window icon
Re-run this only when the source art changes:
.venv\\Scripts\\python packaging\\make_icon.py
"""
from __future__ import annotations
import os
from PIL import Image
_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
_SRC = os.path.join(_ROOT, "docs", "samples", "icon.png")
_ICO = os.path.join(_ROOT, "packaging", "icon.ico")
_PNG_DIR = os.path.join(_ROOT, "cim_suite", "shell", "resources")
_PNG = os.path.join(_PNG_DIR, "app_icon.png")
_ICO_SIZES = [(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)]
def _squared(src_path: str, side: int = 1024) -> Image.Image:
"""Center the (non-square) source on a transparent square canvas, then scale."""
img = Image.open(src_path).convert("RGBA")
edge = max(img.size)
canvas = Image.new("RGBA", (edge, edge), (0, 0, 0, 0))
canvas.paste(img, ((edge - img.width) // 2, (edge - img.height) // 2))
return canvas.resize((side, side), Image.LANCZOS)
def main() -> None:
square = _squared(_SRC)
square.save(_ICO, sizes=_ICO_SIZES)
os.makedirs(_PNG_DIR, exist_ok=True)
square.resize((256, 256), Image.LANCZOS).save(_PNG)
print(f"wrote {_ICO}")
print(f"wrote {_PNG}")
if __name__ == "__main__":
main()