diff --git a/app.py b/app.py index 6abcd9b..73c3c53 100644 --- a/app.py +++ b/app.py @@ -71,6 +71,7 @@ PWA_MANIFEST = { {"src": "/static/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any"}, {"src": "/static/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any"}, {"src": "/static/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable"}, + {"src": "/static/icon-monochrome.png", "sizes": "512x512", "type": "image/png", "purpose": "monochrome"}, ], } diff --git a/scripts/generate-icons.py b/scripts/generate-icons.py new file mode 100644 index 0000000..1228c9d --- /dev/null +++ b/scripts/generate-icons.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +"""Generate PWA icons from the ⚔ (U+2694) brand glyph.""" + +from __future__ import annotations + +from pathlib import Path + +from PIL import Image, ImageDraw, ImageFont + +ROOT = Path(__file__).resolve().parent.parent +STATIC = ROOT / "static" +FONT = "/usr/share/fonts/google-noto-emoji-fonts/NotoEmoji-Regular.ttf" +GLYPH = "\u2694" +BG = (0x1A, 0x1D, 0x27, 255) +FG = (0xE8, 0xEA, 0xF0, 255) + + +def _draw(size: int, *, transparent: bool = False) -> Image.Image: + bg = (0, 0, 0, 0) if transparent else BG + img = Image.new("RGBA", (size, size), bg) + draw = ImageDraw.Draw(img) + font_size = int(size * 0.63) + font = ImageFont.truetype(FONT, font_size) + bbox = draw.textbbox((0, 0), GLYPH, font=font) + tw, th = bbox[2] - bbox[0], bbox[3] - bbox[1] + x = (size - tw) // 2 - bbox[0] + y = (size - th) // 2 - bbox[1] + color = (255, 255, 255, 255) if transparent else FG + draw.text((x, y), GLYPH, font=font, fill=color) + return img + + +def main() -> None: + _draw(512).save(STATIC / "icon-512.png") + _draw(192).save(STATIC / "icon-192.png") + _draw(512, transparent=True).save(STATIC / "icon-monochrome.png") + print("Wrote icon-192.png, icon-512.png, icon-monochrome.png") + + +if __name__ == "__main__": + main() diff --git a/static/favicon.svg b/static/favicon.svg index 70f664a..9f1f4fc 100644 --- a/static/favicon.svg +++ b/static/favicon.svg @@ -1,18 +1,21 @@ - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/static/icon-192.png b/static/icon-192.png index 1a29d72..03c0a2a 100644 Binary files a/static/icon-192.png and b/static/icon-192.png differ diff --git a/static/icon-512.png b/static/icon-512.png index 8d21599..45c43b8 100644 Binary files a/static/icon-512.png and b/static/icon-512.png differ diff --git a/static/icon-monochrome.png b/static/icon-monochrome.png new file mode 100644 index 0000000..2e5668d Binary files /dev/null and b/static/icon-monochrome.png differ diff --git a/static/icon.svg b/static/icon.svg index 7720ef8..65b9d95 100644 --- a/static/icon.svg +++ b/static/icon.svg @@ -1,21 +1,23 @@ - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/static/sw.js b/static/sw.js index fa043bb..ea93022 100644 --- a/static/sw.js +++ b/static/sw.js @@ -1,9 +1,10 @@ -const CACHE = "if-viewer-static-v2"; +const CACHE = "if-viewer-static-v3"; const ASSETS = [ "/static/style.css", "/static/favicon.svg", "/static/icon-192.png", "/static/icon-512.png", + "/static/icon-monochrome.png", "/static/i18n.js", "/static/locales/en.json", "/static/locales/de.json",