54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
|
|
"""Downscale launcher icon PNGs from mipmap-xxxhdpi masters to lower densities."""
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
from PIL import Image
|
||
|
|
|
||
|
|
ROOT = Path(__file__).resolve().parents[1]
|
||
|
|
RES = ROOT / "app" / "src" / "main" / "res"
|
||
|
|
SOURCE_FOLDER = "mipmap-xxxhdpi"
|
||
|
|
|
||
|
|
SOURCES = {
|
||
|
|
"ic_launcher.png": {
|
||
|
|
"mipmap-xxxhdpi": 192,
|
||
|
|
"mipmap-xxhdpi": 144,
|
||
|
|
"mipmap-xhdpi": 96,
|
||
|
|
"mipmap-hdpi": 72,
|
||
|
|
"mipmap-mdpi": 48,
|
||
|
|
},
|
||
|
|
"ic_launcher_foreground.png": {
|
||
|
|
"mipmap-xxxhdpi": 432,
|
||
|
|
"mipmap-xxhdpi": 324,
|
||
|
|
"mipmap-xhdpi": 216,
|
||
|
|
"mipmap-hdpi": 162,
|
||
|
|
"mipmap-mdpi": 108,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> None:
|
||
|
|
for filename, sizes in SOURCES.items():
|
||
|
|
source_path = RES / SOURCE_FOLDER / filename
|
||
|
|
source = Image.open(source_path)
|
||
|
|
expected = sizes[SOURCE_FOLDER]
|
||
|
|
if source.size != (expected, expected):
|
||
|
|
raise RuntimeError(
|
||
|
|
f"{source_path} is {source.size[0]}x{source.size[1]}, expected {expected}x{expected}"
|
||
|
|
)
|
||
|
|
|
||
|
|
for folder, size in sizes.items():
|
||
|
|
if folder == SOURCE_FOLDER:
|
||
|
|
continue
|
||
|
|
out_dir = RES / folder
|
||
|
|
out_dir.mkdir(parents=True, exist_ok=True)
|
||
|
|
resized = source.resize((size, size), Image.Resampling.LANCZOS)
|
||
|
|
resized.save(out_dir / filename)
|
||
|
|
print(f"Wrote {folder}/{filename} ({size}x{size})")
|
||
|
|
|
||
|
|
print("Done.")
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|