Add 19 approved card packages and Timothy revision v03, storing permanent binary assets through Git LFS while keeping generated review images local. Enable harness file polling and verify unchanged used fonts when archiving a previous approved card whose shared font manifest pin has become stale. Preserve the original acceptance manifest and archival verification evidence. Validation: 42 production tests, 9 harness test suites, TypeScript type check, Vite production build, and integrity checks for all 20 card packages passed.
79 lines
4.0 KiB
Python
79 lines
4.0 KiB
Python
"""Retain native source and create diagnostic crops only; no production assembly."""
|
|
from pathlib import Path
|
|
import argparse, hashlib, json, shutil
|
|
from PIL import Image, ImageDraw
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
REPO = next(p for p in ROOT.parents if (p / 'docs/card-art-brief.md').is_file())
|
|
def digest(path):
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('candidate')
|
|
parser.add_argument('generated_path', type=Path)
|
|
parser.add_argument('--parent', default=None)
|
|
parser.add_argument('--crop-vertical-offset', type=float, default=0,
|
|
help='Diagnostic figure-crop offset only; never transforms source art.')
|
|
args = parser.parse_args()
|
|
native = ROOT / 'source' / f'art-native-{args.candidate}.png'
|
|
if native.exists():
|
|
raise SystemExit('Refusing to overwrite an existing native candidate')
|
|
shutil.copy2(args.generated_path, native)
|
|
im = Image.open(native).convert('RGB')
|
|
w, h = im.size
|
|
scale = max(2000 / w, 2800 / h)
|
|
scaled_size = (round(w * scale), round(h * scale))
|
|
scaled = im.resize(scaled_size, Image.Resampling.LANCZOS)
|
|
x, y = (scaled.width - 2000) // 2, (scaled.height - 2800) // 2
|
|
master = ROOT / 'source' / f'art-master-{args.candidate}.png'
|
|
scaled.crop((x, y, x + 2000, y + 2800)).save(master)
|
|
review = ROOT / 'review'
|
|
thumb = im.copy()
|
|
thumb.thumbnail((250, 350), Image.Resampling.LANCZOS)
|
|
thumb.save(review / f'{args.candidate}-thumbnail.png')
|
|
boxes = {
|
|
'figures': (.025, .10, .99, .92),
|
|
'luke-face': (.26, .105, .52, .29),
|
|
'patient-face': (.665, .15, .89, .35),
|
|
'treatment-hands': (.32, .375, .66, .56),
|
|
'patient-resting-hand': (.705, .46, .925, .64),
|
|
'upper-background': (0, 0, 1, .16),
|
|
'doorway-background': (.925, .03, 1, .33),
|
|
'lower-background-and-feet': (0, .80, 1, 1),
|
|
'props-and-bench': (0, .56, .24, .88),
|
|
}
|
|
for label, box in boxes.items():
|
|
if label in {'figures', 'luke-face', 'patient-face', 'treatment-hands', 'patient-resting-hand'}:
|
|
box = (box[0], box[1] + args.crop_vertical_offset, box[2],
|
|
min(1, box[3] + args.crop_vertical_offset))
|
|
crop = im.crop(tuple(round(v * (w if i % 2 == 0 else h)) for i, v in enumerate(box)))
|
|
crop.save(review / f'{args.candidate}-{label}-native.png')
|
|
crop.resize((crop.width * 2, crop.height * 2), Image.Resampling.NEAREST).save(review / f'{args.candidate}-{label}-200.png')
|
|
guide = Image.open(master).convert('RGBA')
|
|
overlay = Image.new('RGBA', guide.size)
|
|
draw = ImageDraw.Draw(overlay)
|
|
layout = json.loads((REPO / 'artifacts/layers/common/v2/layout.json').read_text())
|
|
for bx, by, bw, bh in layout['normalBacking']:
|
|
draw.rectangle((bx, by, bx + bw, by + bh), fill=(90, 30, 40, 150))
|
|
bx, by, bw, bh = layout['focalSafeRegion']
|
|
draw.rectangle((bx, by, bx + bw, by + bh), outline=(0, 210, 150, 255), width=5)
|
|
guide = Image.alpha_composite(guide, overlay)
|
|
guide.thumbnail((500, 700), Image.Resampling.LANCZOS)
|
|
guide.save(review / f'{args.candidate}-layout-guide.png')
|
|
prompt = ROOT / 'source' / f'generation-prompt-{args.candidate}.txt'
|
|
record = {
|
|
'cardId': 'BP-046', 'revision': 'v01', 'candidate': args.candidate,
|
|
'generationMethod': 'built-in image_gen',
|
|
'generationMode': 'selective-edit' if args.parent else 'independent-generation',
|
|
'parent': args.parent, 'lastIndependentGeneration': 'candidate-01',
|
|
'originalImagePath': str(args.generated_path),
|
|
'native': str(native.relative_to(ROOT)), 'nativeDimensions': [w, h], 'nativeSHA256': digest(native),
|
|
'master': str(master.relative_to(ROOT)), 'masterDimensions': [2000, 2800], 'masterSHA256': digest(master),
|
|
'fit': {'scale': scale, 'scaledDimensions': list(scaled_size), 'cropOrigin': [x, y],
|
|
'filter': 'Pillow Lanczos', 'note': 'Uniform fitted review master; upsampled, not native 2000x2800. No grading.'},
|
|
'prompt': str(prompt.relative_to(ROOT)), 'promptSHA256': digest(prompt),
|
|
'selected': False, 'userApproved': False, 'assemblyStarted': False,
|
|
}
|
|
(ROOT / 'source' / f'art-provenance-{args.candidate}.json').write_text(json.dumps(record, indent=2) + '\n')
|
|
print(json.dumps(record, indent=2))
|