Files
hrynco-kswitcher/tools/generate-icon.py
T

24 lines
1.3 KiB
Python

"""Regenerate the native multi-resolution icon (development only; requires Pillow)."""
from pathlib import Path
from PIL import Image, ImageDraw
root = Path(__file__).resolve().parents[1] / 'resources'
# Geometric K: white stem/upper arm, mint lower arm on an indigo keycap.
polygons = [('#FFFFFF', [(8, 7), (12, 7), (12, 25), (8, 25)]),
('#FFFFFF', [(11, 15), (22, 6), (25, 9), (14, 18)]),
('#5EEAD4', [(11, 14), (25, 24), (22, 27), (10, 18)])]
svg = '<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 32 32">\n'
svg += '<rect x="1" y="1" width="30" height="30" rx="7" fill="#4F46E5"/>\n'
for color, points in polygons:
svg += '<polygon fill="' + color + '" points="' + ' '.join(f'{x},{y}' for x,y in points) + '"/>\n'
(root / 'kswitcher.svg').write_text(svg + '</svg>\n', encoding='utf-8')
scale = 32
im = Image.new('RGBA', (32*scale, 32*scale))
draw = ImageDraw.Draw(im)
draw.rounded_rectangle((scale, scale, 31*scale, 31*scale), radius=7*scale, fill='#4F46E5')
for color, points in polygons:
draw.polygon([(x*scale,y*scale) for x,y in points], fill=color)
im = im.resize((256,256),Image.Resampling.LANCZOS)
im.save(root / 'kswitcher.png')
im.save(root / 'kswitcher.ico', sizes=[(s,s) for s in (16,20,24,32,40,48,64,128,256)])