make_images.py
"""Render 1000x750 portfolio cards from real local evidence. No stock assets."""
import json,argparse
from pathlib import Path
from PIL import Image,ImageDraw,ImageFont
ROOT=Path(__file__).resolve().parent
BG='#eff3f8'; NAVY='#14283f'; MUTED='#536a80'; GREEN='#087c64'; RED='#b83f48'; AMBER='#976400'; LINE='#d8e1ec'
def font(size,bold=False,mono=False):
names=['consola.ttf','DejaVuSansMono.ttf'] if mono else (['segoeuib.ttf','DejaVuSans-Bold.ttf'] if bold else ['segoeui.ttf','DejaVuSans.ttf'])
for name in names:
try: return ImageFont.truetype(name,size)
except OSError: pass
return ImageFont.load_default(size=size)
def text(d,xy,value,size=20,fill=NAVY,bold=False,mono=False,max_width=None):
f=font(size,bold,mono)
if max_width is not None:
while d.textbbox((0,0),value,font=f)[2]>max_width and size>13: size-=1; f=font(size,bold,mono)
if d.textbbox((0,0),value,font=f)[2]>max_width: raise ValueError('Text exceeds card: '+value)
d.text(xy,value,font=f,fill=fill)
def card(title,subtitle):
im=Image.new('RGB',(1000,750),BG); d=ImageDraw.Draw(im)
d.rectangle((0,0,1000,13),fill=GREEN); text(d,(44,35),'SYNTHETIC PORTFOLIO DEMO',15,GREEN,True)
text(d,(44,69),title,36,bold=True,max_width=912); text(d,(44,121),subtitle,19,MUTED,max_width=912)
return im,d
def panel(d,box,fill='white'): d.rounded_rectangle(box,16,fill=fill)
def footer(d,left,right):
d.line((44,692,956,692),fill=LINE,width=2); text(d,(44,708),left,15,MUTED,max_width=660); text(d,(752,708),right,15,GREEN,True,max_width=204)
def save(im,root,name):
(root/'images').mkdir(exist_ok=True); im.save(root/'images'/name)
def load(root,name): return json.loads((root/name).read_text(encoding='utf-8'))
def sheets():
root=ROOT; demo=load(root,'evidence/demo.json'); tests=load(root,'evidence/tests.json'); r=demo['repaired']
im,d=card('Google Sheets CRM repair','Replay-safe ingestion, explicit dates and protected manual columns')
metrics=[(str(demo['inputRows']),'input submissions'),(str(r['inserted']),'new leads'),(str(r['duplicates']),'duplicates skipped'),(str(r['rejected']),'rows to review')]
for i,(n,label) in enumerate(metrics):
x=44+i*232; panel(d,(x,174,x+216,286)); text(d,(x+18,186),n,38,bold=True); text(d,(x+18,244),label,17,MUTED)
for x,title,color,lines in [(44,'BEFORE: defect reproduced',RED,['Repeated triggers append duplicates','Host parser guesses 03/04/2026','Row writes exhaust mock quota','A:H rewrite erases notes/formula','No structured diagnostic log']),
(508,'AFTER: regression checked',GREEN,['Lock + email/submission dedupe','Strict dates + explicit timezone','Batch writes + resumable cursor','A:F ownership; manual G:H kept','Dry-run + structured failure codes'])]:
panel(d,(x,314,x+448,568)); text(d,(x+20,331),title,20,color,True,max_width=410)
for i,line in enumerate(lines): text(d,(x+20,378+i*35),line,18,max_width=410)
panel(d,(44,591,956,668),NAVY); text(d,(64,604),f"{tests['passed']}/{tests['passed']+tests['failed']} tests pass",26,'white',True)
text(d,(340,610),f"{demo['finalLeads']} final leads | {demo['replay']['inserted']} added on replay",23,'white',max_width=590)
footer(d,'Real local outputs: evidence/demo.json and evidence/tests.json','Node mocks only'); save(im,root,'01-before-after.png')
im,d=card('Replay and recovery evidence','Actual regression assertions from the offline Apps Script service mocks')
selected=[('Double-fired trigger + cursor reset','double-fired'),('Competing execution rejected by lock','competing'),('Quota error releases lock; retry recovers','quota failure leaves'),('Write succeeds; checkpoint fails; replay safe','crash after write'),('80 rows in 2 writes; next run resumes','bounded chunks'),('Elapsed budget defers safely','elapsed time')]
panel(d,(44,174,956,480))
for i,(label,needle) in enumerate(selected):
result=next(x for x in tests['results'] if needle in x['name']); y=193+i*45
text(d,(64,y),result['status'],18,GREEN,True); text(d,(145,y),label,21,max_width=784)
panel(d,(44,505,956,665),NAVY); text(d,(64,520),'Preserved client-owned cells',19,'#9bdcca',True)
text(d,(64,556),'G2: '+demo['ownerNote'],21,'white',mono=True); text(d,(64,591),'H2: '+demo['ownerFormula'],21,'white',mono=True)
text(d,(494,553),'Structured logs include row + code.',18,'white'); text(d,(494,590),'Contact values omitted from logs.',18,'white')
footer(d,'Tests and written handoff; AI coding tools','No Google deployment'); save(im,root,'02-verification.png')
return root
if __name__=='__main__':
sheets()
print('Rendered two evidence-based PNGs, 1000x750, in images/')