#!/usr/bin/env python3 """Le miniature della mappa: ogni sfondo di assets/scenes/ rimpicciolito a 128x72 in assets/scenes/mini/. python3 tools/miniature.py (make miniature; rifà solo quelle più vecchie del loro sfondo) Si riduce con la media dei pixel (non a punti): a quella misura la pixel art si legge meglio. """ from pathlib import Path from PIL import Image ROOT = Path(__file__).resolve().parent.parent SCENES, MINI = ROOT / 'assets' / 'scenes', ROOT / 'assets' / 'scenes' / 'mini' SIZE = (128, 72) def main(): MINI.mkdir(exist_ok=True) done = 0 for src in sorted(SCENES.glob('*.png')): dst = MINI / src.name if dst.exists() and dst.stat().st_mtime >= src.stat().st_mtime: continue img = Image.open(src).convert('RGB') # Le panoramiche (più larghe di 16:9) si prendono dal centro. w, h = img.size cw = min(w, round(h * 16 / 9)) img = img.crop(((w - cw) // 2, 0, (w - cw) // 2 + cw, h)).resize(SIZE, Image.Resampling.BOX) # 64 colori come gli sfondi: il file pesa un terzo. img.quantize(64, dither=Image.Dither.NONE).save(dst, optimize=True) done += 1 print(f'{done} miniature in {MINI.relative_to(ROOT)}') if __name__ == '__main__': main()