#!/usr/bin/env python3 from __future__ import annotations import struct import sys from pathlib import Path PNG_SIGNATURE = b"\x89PNG\r\n\x1a\n" def main() -> int: if len(sys.argv) != 3: print("usage: generate_ico_from_png.py ", file=sys.stderr) return 1 source = Path(sys.argv[1]) target = Path(sys.argv[2]) png = source.read_bytes() if not png.startswith(PNG_SIGNATURE): print(f"{source} is not a PNG file", file=sys.stderr) return 1 width = int.from_bytes(png[16:20], "big") height = int.from_bytes(png[20:24], "big") width_byte = 0 if width >= 256 else width height_byte = 0 if height >= 256 else height header = struct.pack("