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.
69 lines
3.5 KiB
Python
69 lines
3.5 KiB
Python
"""Retain lossless art and produce illustration-only review evidence."""
|
|
from pathlib import Path
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import 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())
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('candidate')
|
|
parser.add_argument('generated_path', type=Path)
|
|
parser.add_argument('--parent', help='Immediate source candidate for an edit')
|
|
args = parser.parse_args()
|
|
candidate = args.candidate
|
|
native = ROOT / 'source' / f'art-native-{candidate}.png'
|
|
if native.exists():
|
|
raise SystemExit('Refusing to overwrite retained native')
|
|
shutil.copy2(args.generated_path, native)
|
|
im = Image.open(native).convert('RGB')
|
|
w, h = im.size
|
|
scale = max(2000 / w, 2800 / h)
|
|
dims = (round(w * scale), round(h * scale))
|
|
x, y = (dims[0] - 2000) // 2, (dims[1] - 2800) // 2
|
|
master = ROOT / 'source' / f'art-master-{candidate}.png'
|
|
im.resize(dims, Image.Resampling.LANCZOS).crop((x,y,x+2000,y+2800)).save(master)
|
|
review = ROOT / 'review'
|
|
for label, size in [('standard',(1000,1400)),('thumbnail',(250,350))]:
|
|
preview = im.copy()
|
|
preview.thumbnail(size, Image.Resampling.LANCZOS)
|
|
preview.save(review / f'{candidate}-{label}.png')
|
|
crop_path = ROOT / 'source' / f'review-crops-{candidate}.json'
|
|
boxes = json.loads(crop_path.read_text())
|
|
for label, box in boxes.items():
|
|
crop = im.crop(tuple(round(v*(w if i%2==0 else h)) for i,v in enumerate(box)))
|
|
crop.save(review / f'{candidate}-{label}-native.png')
|
|
crop.resize((crop.width*2,crop.height*2), Image.Resampling.NEAREST).save(review / f'{candidate}-{label}-200.png')
|
|
guide = Image.open(master).convert('RGBA')
|
|
overlay = Image.new('RGBA', guide.size)
|
|
draw = ImageDraw.Draw(overlay)
|
|
layout_path = REPO / 'artifacts/layers/common/v2/layout.json'
|
|
layout = json.loads(layout_path.read_text())
|
|
for bx,by,bw,bh in layout['normalBacking']:
|
|
draw.rectangle((bx,by,bx+bw,by+bh), fill=(90,30,40,150))
|
|
draw.rectangle((0,0,2000,2800),outline=(90,30,40,150),width=layout['perimeterWidth'])
|
|
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'{candidate}-layout-guide.png')
|
|
def digest(p):
|
|
return hashlib.sha256(p.read_bytes()).hexdigest()
|
|
prompt = ROOT / 'source' / f'generation-prompt-{candidate}.txt'
|
|
record = {
|
|
'cardId':'BP-058','revision':'v01','candidate':candidate,
|
|
'generationMethod':'built-in image_gen','generationMode':'selective-edit' if args.parent else 'independent-generation',
|
|
'parent':args.parent,'lastIndependentGeneration':'candidate-01' if args.parent else candidate,
|
|
'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(dims),'cropOrigin':[x,y],'filter':'Pillow Lanczos','note':'Uniform fit for review only, no grading. Master size does not imply native generation resolution.'},
|
|
'prompt':str(prompt.relative_to(ROOT)),'promptSHA256':digest(prompt),
|
|
'reviewCropBoxes':boxes,'layoutGuide':str(layout_path.relative_to(REPO)),
|
|
'selected':False,'userApproved':False,'assemblyStarted':False
|
|
}
|
|
(ROOT / 'source' / f'art-provenance-{candidate}.json').write_text(json.dumps(record,indent=2)+'\n')
|
|
print(json.dumps(record,indent=2))
|