34 lines
973 B
Python
Executable File
34 lines
973 B
Python
Executable File
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import struct
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def main() -> int:
|
|
if len(sys.argv) != 3:
|
|
raise SystemExit("usage: png-to-icns ICONSET_DIR OUTPUT.icns")
|
|
iconset = Path(sys.argv[1])
|
|
output = Path(sys.argv[2])
|
|
resources = [
|
|
(b"icp4", "icon_16x16.png"),
|
|
(b"icp5", "icon_32x32.png"),
|
|
(b"icp6", "icon_32x32@2x.png"),
|
|
(b"ic07", "icon_128x128.png"),
|
|
(b"ic08", "icon_256x256.png"),
|
|
(b"ic09", "icon_512x512.png"),
|
|
(b"ic10", "icon_512x512@2x.png"),
|
|
]
|
|
blocks: list[bytes] = []
|
|
for resource_type, filename in resources:
|
|
payload = (iconset / filename).read_bytes()
|
|
blocks.append(resource_type + struct.pack(">I", len(payload) + 8) + payload)
|
|
body = b"".join(blocks)
|
|
output.write_bytes(b"icns" + struct.pack(">I", len(body) + 8) + body)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|