#!/usr/bin/env python3 """Verify exported Isaac printings against their declared visible components.""" import json from pathlib import Path import numpy as np from PIL import Image, ImageDraw, ImageFont ROOT = Path(__file__).resolve().parents[1] REPO = next(p for p in ROOT.parents if (p / 'docs/card-layer-pipeline.md').is_file()) card = json.loads((ROOT / 'card.json').read_text()) art = Image.open(REPO / card['art']).convert('RGBA') text = Image.open(ROOT / 'source/text/text-2000.png').convert('RGBA') layers = REPO / 'artifacts/layers/uncommon/v3/exports' printings = {'normal': ('overlay-normal', True), 'boundless': (None, False), 'borderless': ('backing-borderless', True), 'textless': ('frame-textless', False)} checks = [] for printing, (component, has_text) in printings.items(): overlay = Image.open(layers / f'{component}-2000.png').convert('RGBA') if component else None expected = Image.alpha_composite(art, overlay) if overlay else art.copy() if has_text: expected = Image.alpha_composite(expected, text) for resolution, width in [('low', 500), ('med', 1000), ('high', 2000)]: dims = (width, width * 7 // 5) folder = ROOT / resolution / printing for filename in ['card.png', 'finish-mask.png', 'text-mask.png']: im = Image.open(folder / filename).convert('RGBA') assert im.size == dims, (folder, filename, 'dimensions') assert im.getchannel('A').getextrema() == (255, 255), (folder, filename, 'opacity') a = np.asarray(im) if filename != 'card.png': assert np.array_equal(a[:, :, 0], a[:, :, 1]) and np.array_equal(a[:, :, 1], a[:, :, 2]), 'Non-grayscale map' else: assert np.array_equal(a, np.asarray(expected.resize(dims, Image.Resampling.LANCZOS))), 'Composition mismatch' if filename == 'text-mask.png' and not has_text: assert im.getchannel('R').getextrema() == (0, 0), 'Stale text protection' checks.append({'file': str((folder / filename).relative_to(ROOT)), 'dimensions': list(dims), 'pass': True}) fm = np.asarray(Image.open(ROOT / 'high' / printing / 'finish-mask.png').getchannel('R')) if overlay: assert np.all(fm[np.asarray(overlay.getchannel('A')) == 255] == 0), 'Finish on opaque overlay' if not has_text: assert np.count_nonzero(fm[2250:2650, 200:1800]) > 0, 'Absent backing still suppresses all finish' for kind in ['finish-mask', 'text-mask']: board = Image.new('RGB', (1200, 480), '#11161c') draw = ImageDraw.Draw(board) font = ImageFont.truetype(str(REPO / 'fonts/P052-Bold.otf'), 22) for i, printing in enumerate(printings): draw.text((300 * i + 10, 8), printing.title(), fill='#f4ead4', font=font) im = Image.open(ROOT / 'med' / printing / f'{kind}.png').convert('RGB') board.paste(im.resize((280, 392), Image.Resampling.BILINEAR), (300 * i + 10, 50)) board.save(ROOT / 'review' / f'{kind}s-comparison.png') normal = Image.open(ROOT / 'high/normal/card.png') normal.crop((0, 0, 2000, 380)).save(ROOT / 'review/normal-header-master.png') normal.crop((0, 2160, 2000, 2800)).save(ROOT / 'review/normal-footer-master.png') report = {'status': 'passed', 'filesChecked': len(checks), 'checks': checks, 'compositionPixelsMatchDeclaredComponents': True, 'boundlessMatchesApprovedMaster': True, 'opaqueOverlaysHaveZeroFinish': True, 'textlessAndBoundlessTextMasksAreZero': True, 'removedBackingsRecoverFinish': True, 'movingLight': 'not performed', 'harnessFixturesInstalled': False} (ROOT / 'review/assembly-validation.json').write_text(json.dumps(report, indent=2) + '\n') print('Passed: 36 PNGs; decoded printing composition, mask conventions, dimensions and opacity.') # Non-production guide: actual ink rectangles and baselines from the renderer. build = json.loads((ROOT / 'review/build-validation.json').read_text()) guide = Image.open(ROOT / 'high/normal/card.png').convert('RGB') draw = ImageDraw.Draw(guide) for glyph in build['typography']['glyphs']: draw.rectangle(glyph['unclippedInkBounds'], outline='#d52438', width=3) draw.line((140, glyph['baseline'], 1860, glyph['baseline']), fill='#2479dd', width=2) line_top, line_bottom = build['typography']['referenceLineBox'] draw.rectangle((160, line_top, 1840, line_bottom), outline='#199047', width=3) guide.resize((1000, 1400), Image.Resampling.LANCZOS).save(ROOT / 'review/typography-guide.png')