Mulberry/packaging/make_icons.py
Mulberry 615b21d64a
Mulberry 1.1.0: Material You music player for Linux and Windows
- KDE/Windows accent-driven Material 3 theme, live updating
- Library, tabbed playlists, smart/saved lists, queue, ratings
- mpv and Qt Multimedia engines, EQ, ReplayGain, gapless
- Synced lyrics (LRCLIB, NetEase, local .lrc), covers, MusicBrainz tags
- Last.fm/ListenBrainz scrobbling, MPRIS, Windows media keys
- Audio CD playback and ripping
- PyInstaller, Inno Setup and AppImage builds via GitHub Actions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J7imThHV9BMkG24GaxPDeq
2026-10-09 23:00:48 -05:00

52 lines
1.7 KiB
Python

"""Render mulberry/assets/mulberry.svg into PNG sizes and a Windows .ico."""
import sys
from pathlib import Path
from PyQt6.QtCore import QBuffer, QByteArray, QIODevice
from PyQt6.QtGui import QGuiApplication, QImage, QPainter
from PyQt6.QtSvg import QSvgRenderer
ROOT = Path(__file__).resolve().parent.parent
OUT = ROOT / "packaging" / "build-icons"
def render(r, size):
img = QImage(size, size, QImage.Format.Format_ARGB32)
img.fill(0)
p = QPainter(img)
r.render(p)
p.end()
return img
def main():
QGuiApplication(sys.argv[:1] + ["-platform", "offscreen"])
OUT.mkdir(parents=True, exist_ok=True)
r = QSvgRenderer(str(ROOT / "mulberry" / "assets" / "mulberry.svg"))
pngs = {}
for s in (16, 24, 32, 48, 64, 128, 256, 512):
img = render(r, s)
img.save(str(OUT / f"mulberry-{s}.png"))
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QIODevice.OpenModeFlag.WriteOnly)
img.save(buf, "PNG")
pngs[s] = bytes(ba)
# ICO with embedded PNGs (Vista+ format)
sizes = [16, 24, 32, 48, 64, 128, 256]
header = (0).to_bytes(2, "little") + (1).to_bytes(2, "little") + len(sizes).to_bytes(2, "little")
entries, data = b"", b""
offset = 6 + 16 * len(sizes)
for s in sizes:
d = pngs[s]
dim = 0 if s >= 256 else s
entries += bytes([dim, dim, 0, 0]) + (1).to_bytes(2, "little") + (32).to_bytes(2, "little") \
+ len(d).to_bytes(4, "little") + offset.to_bytes(4, "little")
data += d
offset += len(d)
(OUT / "mulberry.ico").write_bytes(header + entries + data)
print("icons written to", OUT)
if __name__ == "__main__":
main()