52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Preview transparent assets at 96px and 64px on light and dark surfaces."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
from PIL import Image, ImageDraw
|
|
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--input-dir", type=Path, required=True)
|
|
parser.add_argument("--pattern", default="*@2x.png")
|
|
parser.add_argument("--output", type=Path, required=True)
|
|
return parser.parse_args()
|
|
|
|
|
|
def main() -> None:
|
|
args = parse_args()
|
|
files = sorted(args.input_dir.glob(args.pattern))
|
|
if not files:
|
|
raise SystemExit("no assets")
|
|
cell_w, cell_h, cols = 370, 210, 3
|
|
rows = (len(files) + cols - 1) // cols
|
|
sheet = Image.new("RGB", (cols * cell_w, rows * cell_h), (27, 32, 42))
|
|
draw = ImageDraw.Draw(sheet)
|
|
for index, path in enumerate(files):
|
|
x, y = (index % cols) * cell_w, (index // cols) * cell_h
|
|
asset = Image.open(path).convert("RGBA")
|
|
for offset, size, bg in (
|
|
(20, 96, (244, 240, 224)),
|
|
(195, 64, (31, 38, 50)),
|
|
):
|
|
panel = Image.new("RGBA", (145, 130), bg + (255,))
|
|
icon = asset.resize((size, size), Image.Resampling.LANCZOS)
|
|
panel.alpha_composite(icon, ((145 - size) // 2, (130 - size) // 2))
|
|
sheet.paste(panel.convert("RGB"), (x + offset, y + 12))
|
|
parts = path.stem.removesuffix("@2x").split("_", 2)
|
|
draw.text((x + 20, y + 150), "_".join(parts[:2]), fill=(244, 240, 224))
|
|
draw.text((x + 20, y + 168), parts[2], fill=(200, 208, 218))
|
|
draw.text((x + 60, y + 188), "96px", fill=(160, 174, 190))
|
|
draw.text((x + 238, y + 188), "64px", fill=(160, 174, 190))
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
sheet.save(args.output, optimize=True)
|
|
print(f"ASSET_SCALE_PREVIEW_OK assets={len(files)} output={args.output}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|