Files
Agent-Workbench/scripts/generate-desktop-icon.py

29 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Generate the product's deterministic original bracket/workbench icon (PNG and ICO)."""
import pathlib
import struct
import zlib
size = 256
rows = []
for y in range(size):
row = bytearray([0])
for x in range(size):
color = (28, 64, 115, 255)
if (46 <= x < 64 and 64 <= y < 192 or 46 <= x < 98 and (64 <= y < 82 or 174 <= y < 192)
or 192 <= x < 210 and 64 <= y < 192 or 158 <= x < 210 and (64 <= y < 82 or 174 <= y < 192)):
color = (238, 246, 255, 255)
if 100 <= x < 156 and 119 <= y < 137:
color = (105, 182, 247, 255)
row.extend(color)
rows.append(bytes(row))
def chunk(tag, value):
return struct.pack('>I', len(value)) + tag + value + struct.pack('>I', zlib.crc32(tag + value))
png = (b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', struct.pack('>IIBBBBB', size, size, 8, 6, 0, 0, 0))
+ chunk(b'IDAT', zlib.compress(b''.join(rows), 9)) + chunk(b'IEND', b''))
root = pathlib.Path(__file__).resolve().parent.parent / 'public'
(root / 'workbench-icon.png').write_bytes(png)
(root / 'workbench-icon.ico').write_bytes(struct.pack('<HHH', 0, 1, 1) + struct.pack('<BBBBHHII', 0, 0, 0, 0, 1, 32, len(png), 22) + png)
print('Original desktop icon generated: PNG and ICO, 256 × 256.')