ohmu
·
2026-10-15
1#!/bin/sh
2# Convert logo.svg to logo.ico.
3#
4# Every frame is stored as PNG. ImageMagick's ICO writer only uses PNG for frames that are
5# 256x256 or larger and falls back to an uncompressed DIB for everything smaller, which
6# inflates the icon from ~19 KB to ~108 KB (and to ~370 KB on ImageMagick 7, which also
7# stores 256x256 as a DIB). Packing the frames here keeps the icon small and predictable.
8set -e
9
10cd "$(dirname "$0")"
11
12for size in 16 32 48 64 128 256; do
13 rsvg-convert -w "$size" -h "$size" ../../logo/logo.svg > "logo$size.png"
14done
15
16python3 - <<'PY'
17import struct
18
19sizes = [16, 32, 48, 64, 128, 256]
20frames = [open(f"logo{s}.png", "rb").read() for s in sizes]
21
22header = struct.pack("<HHH", 0, 1, len(sizes))
23offset = 6 + 16 * len(sizes)
24entries = b""
25for size, frame in zip(sizes, frames):
26 dim = 0 if size == 256 else size # 0 means 256 in the ICO directory
27 entries += struct.pack("<BBBBHHII", dim, dim, 0, 0, 1, 32, len(frame), offset)
28 offset += len(frame)
29
30with open("logo.ico", "wb") as f:
31 f.write(header + entries + b"".join(frames))
32PY
33
34rm logo16.png logo32.png logo48.png logo64.png logo128.png logo256.png