Files
personal-website/scripts/check-game-images.py
Stan Runge c2ba8febb4
Some checks failed
Test and deploy staging / staging (push) Failing after 5m29s
Expand website and game trackers
2026-09-25 22:43:04 +00:00

33 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""Check picture coverage, decodability, dimensions, and manifest integrity offline."""
import json
from pathlib import Path
from PIL import Image
ROOT=Path(__file__).resolve().parents[1]
manifest=json.loads((ROOT/'data/game-images.json').read_text())
paths={r['path'] for r in manifest}
assert len(paths)==len(manifest), 'Duplicate image paths'
for game in json.loads((ROOT/'data/pokemon-catalog.json').read_text())['games']:
assert f'/game-logos/pokemon/{game["slug"]}.webp' in paths, game['slug']
for game in json.loads((ROOT/'data/call-of-duty.json').read_text())['games']:
assert f'/game-logos/cod/{game["slug"]}.webp' in paths, game['slug']
for kind in ['sprite','shiny','artwork']:
for number in range(1,1026):assert f'/game-art/pokemon/{kind}/{number}.webp' in paths
for slug in ['pokemon','call-of-duty','osu']:assert f'/game-logos/{slug}.webp' in paths
for row in json.loads((ROOT/'data/cod-art.json').read_text()):
assert row['path'] in paths, (row['game'],row['name'])
for path in json.loads((ROOT/'data/cod-achievement-art.json').read_text()).values():
assert path in paths, path
for region,m in json.loads((ROOT/'data/pokemon-map-art.json').read_text()).items():
paths.add(m['image'])
for point in m['nodes']:
assert 0 <= point['x'] <= m['width'] and 0 <= point['y'] <= m['height'], (region,point)
for_size=Image.open(ROOT/'static'/m['image'].lstrip('/'))
assert for_size.size==(m['width'],m['height']),region
for path in paths:
with Image.open(ROOT/'static'/path.lstrip('/')) as im:
assert im.format=='WEBP',path
im.load()
assert min(im.size)>0,path
print(f'{len(paths):,} local WebP images checked: all game pictures, 1,025 × 3 Pokémon images, 13 maps, and downloaded COD artwork.')