33 lines
1.5 KiB
Python
33 lines
1.5 KiB
Python
"""Resize the approved MeshPort artwork into native platform icon assets.
|
|
|
|
Requires Pillow. No generation or creative editing of the source artwork.
|
|
"""
|
|
import json
|
|
from pathlib import Path
|
|
from PIL import Image
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
APP = ROOT / "apps/meshport_lab"
|
|
source = Image.open(ROOT / "outputs/branding/meshport-logo-v1.png").convert("RGBA")
|
|
|
|
def write_icon(path, size, opaque=False):
|
|
image = source.resize((size, size), Image.Resampling.LANCZOS)
|
|
if opaque:
|
|
background = Image.new("RGBA", image.size, "#087d8e")
|
|
background.alpha_composite(image)
|
|
image = background.convert("RGB")
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
image.save(path)
|
|
|
|
for platform in ("macos", "ios"):
|
|
directory = APP / platform / "Runner/Assets.xcassets/AppIcon.appiconset"
|
|
for item in json.loads((directory / "Contents.json").read_text())["images"]:
|
|
if "filename" in item:
|
|
pixels = round(float(item["size"].split("x")[0]) * float(item["scale"].rstrip("x")))
|
|
write_icon(directory / item["filename"], pixels, opaque=platform == "ios")
|
|
|
|
for density, size in {"mdpi": 48, "hdpi": 72, "xhdpi": 96, "xxhdpi": 144, "xxxhdpi": 192}.items():
|
|
write_icon(APP / f"android/app/src/main/res/mipmap-{density}/ic_launcher.png", size)
|
|
source.save(APP / "windows/runner/resources/app_icon.ico", sizes=[(16,16), (32,32), (48,48), (64,64), (128,128), (256,256)])
|
|
write_icon(APP / "assets/branding/meshport.png", 256)
|