summaryrefslogtreecommitdiff
path: root/icon
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2026-03-04 21:07:22 +0100
committerxengineering <me@xengineering.eu>2026-03-04 21:18:43 +0100
commitda482d1327360f814c0f63f876d655e8001deb10 (patch)
treeef873ef815a6e152ab04a8cdcb52c04b5b0ffa9f /icon
parent181ab8ddcb7ebfc836057050bcda0199c27081c7 (diff)
downloadsia-app-da482d1327360f814c0f63f876d655e8001deb10.tar
sia-app-da482d1327360f814c0f63f876d655e8001deb10.tar.zst
sia-app-da482d1327360f814c0f63f876d655e8001deb10.zip
icon: Add convert.py for Android Adaptive Icons
Android Adaptive Icons allow the OS to display the icon in different variations and styles. For this to work Android requires PNG images with e.g. only the foreground or only the background. The added script can generate these files from main.svg. [1]: https://developer.android.com/develop/ui/views/launch/icon_design_adaptive
Diffstat (limited to 'icon')
-rwxr-xr-xicon/convert.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/icon/convert.py b/icon/convert.py
new file mode 100755
index 0000000..b550709
--- /dev/null
+++ b/icon/convert.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python3
+
+
+import argparse
+import dataclasses
+import os
+import pathlib
+import subprocess
+import sys
+
+DESCRIPTION = "Script to convert main icon file to all required formats"
+SCRIPT = pathlib.Path(__file__).resolve()
+ICON = SCRIPT.parent
+MAIN = ICON / "main.svg"
+ANDROID = ICON / "android"
+
+
+def main() -> None:
+ _ = Arguments.from_list(sys.argv)
+
+ os.makedirs(ANDROID, exist_ok=True)
+ inkscape(MAIN, ANDROID / "default.png")
+ inkscape(MAIN, ANDROID / "foreground.png", ids=("foreground",))
+ inkscape(MAIN, ANDROID / "background.png", ids=("background",))
+
+
+@dataclasses.dataclass(frozen=True, kw_only=True)
+class Arguments:
+
+ @staticmethod
+ def from_list(args: list[str]) -> "Arguments":
+ parser = argparse.ArgumentParser(description=DESCRIPTION)
+
+ parser.parse_args(args[1:])
+
+ return Arguments()
+
+
+def inkscape(
+ source: pathlib.Path,
+ sink: pathlib.Path,
+ ids: tuple[str, ...] = ("foreground", "background"),
+ width: int = 1024,
+ height: int = 1024,
+) -> None:
+ subprocess.run(
+ (
+ # fmt: off
+ "inkscape", str(source),
+ "--export-filename", str(sink),
+ "--export-area-page",
+ "--export-id", ";".join(ids),
+ "--export-width", str(width),
+ "--export-height", str(height),
+ "--export-id-only",
+ # fmt: on
+ ),
+ check=True,
+ shell=False,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ )
+
+
+if __name__ == "__main__":
+ main()