"""Export approved raster originals; preserve alpha and never alter source art.""" from pathlib import Path import json from PIL import Image root = Path(__file__).resolve().parents[1] sources = root / 'artwork/seals/great-migration' destination = root / 'web/assets/seals' destination.mkdir(parents=True, exist_ok=True) manifest = {} catalogue = json.loads((sources / 'catalogue.json').read_text()) for source in sorted(sources.glob('*-v1.png')): with Image.open(source) as image: if 'A' not in image.getbands() or image.getchannel('A').getextrema()[0] != 0: raise ValueError(f'Missing transparency: {source.name}') for size in (150, 300): output = destination / f'{source.stem}-{size}.png' image.convert('RGBA').resize((size, size), Image.Resampling.LANCZOS).save(output, optimize=True) manifest[source.stem] = {**catalogue[source.stem], 'footer150': f'/assets/seals/{source.stem}-150.png', 'standard300': f'/assets/seals/{source.stem}-300.png'} (sources / 'export-manifest.json').write_text(json.dumps(manifest, indent=2)+'\n') print(f'Exported {len(manifest)} transparent seals in two sizes')