Files

44 lines
1.3 KiB
Python
Raw Permalink Normal View History

import sys
from pathlib import Path
from PIL import Image, ImageDraw
SIZES = (16, 32, 48, 128)
SCALE = 8
BACKGROUND = (17, 43, 94, 255)
GLYPH = (234, 242, 255, 255)
CENTER = (0.5, 0.5)
OUTER = ((0.5, 0.2), (0.24, 0.68), (0.76, 0.68))
CORNER_RADIUS = 0.22
CENTER_RADIUS = 0.1
OUTER_RADIUS = 0.075
LINE_WIDTH = 0.04
def render(size: int) -> Image.Image:
big = size * SCALE
image = Image.new("RGBA", (big, big), (0, 0, 0, 0))
draw = ImageDraw.Draw(image)
draw.rounded_rectangle((0, 0, big - 1, big - 1), radius=big * CORNER_RADIUS, fill=BACKGROUND)
def point(pair):
return (pair[0] * big, pair[1] * big)
for outer in OUTER:
draw.line((point(CENTER), point(outer)), fill=GLYPH, width=max(1, round(LINE_WIDTH * big)))
for pair, radius in [(CENTER, CENTER_RADIUS)] + [(outer, OUTER_RADIUS) for outer in OUTER]:
x, y = point(pair)
r = radius * big
draw.ellipse((x - r, y - r, x + r, y + r), fill=GLYPH)
return image.resize((size, size), Image.LANCZOS)
def main(out_dir: Path) -> None:
out_dir.mkdir(parents=True, exist_ok=True)
for size in SIZES:
render(size).save(out_dir / f"icon-{size}.png", optimize=True)
if __name__ == "__main__":
main(Path(sys.argv[1]) if len(sys.argv) > 1 else Path(__file__).resolve().parent.parent / "icons")