"""Draws the two app icons (.ico, .icns) with Pillow: python packaging/make_icons.py""" import sys from pathlib import Path from PIL import Image, ImageDraw HERE = Path(__file__).resolve().parent S = 256 def base(bg="#161a20"): im = Image.new("RGBA", (S, S), (0, 0, 0, 0)) d = ImageDraw.Draw(im) d.rounded_rectangle((8, 8, S - 8, S - 8), radius=52, fill=bg) return im, d def bars(d, x0, y0, scale, color="#38bdf8"): # the WebUI logo: four level bars for x, top in ((7, 10), (13, 6), (19, 14), (25, 9)): d.line(((x0 + x * scale, y0 + 22 * scale), (x0 + x * scale, y0 + top * scale)), fill=color, width=int(3 * scale)) d.ellipse((x0 + x * scale - 1.5 * scale, y0 + top * scale - 1.5 * scale, x0 + x * scale + 1.5 * scale, y0 + top * scale + 1.5 * scale), fill=color) d.ellipse((x0 + x * scale - 1.5 * scale, y0 + 22 * scale - 1.5 * scale, x0 + x * scale + 1.5 * scale, y0 + 22 * scale + 1.5 * scale), fill=color) def app_icon(): im, d = base() bars(d, 0, 12, 8) return im def writer_icon(): im, d = base() # SD card outline with cut corner d.polygon([(70, 40), (160, 40), (190, 70), (190, 216), (70, 216)], fill="#e8edf3") for i in range(5): d.rectangle((86 + i * 19, 52, 96 + i * 19, 82), fill="#c0841a") bars(d, 74, 98, 3.6, color="#0284c7") # Raspberry-red write arrow d.polygon([(196, 150), (232, 150), (214, 182)], fill="#e11d48") d.rectangle((207, 112, 221, 152), fill="#e11d48") return im for name, im in (("dsp-control.ico", app_icon()), ("pi-writer.ico", writer_icon())): im.save(HERE / name, sizes=[(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)]) im.save(HERE / name.replace(".ico", ".png")) if sys.platform == "darwin": # the macOS app icon, only needed (and built) there im.resize((1024, 1024), Image.LANCZOS).save(HERE / name.replace(".ico", ".icns")) print("wrote", name)