"""Assemble measured HEL-743 search/header crops, sample left and actual right.""" from pathlib import Path import json from PIL import Image, ImageDraw root=Path(__file__).resolve().parents[1] out=root/'e2e/shots/hel743' rows=json.loads((out/'results.json').read_text())['measurements'] for width in (1440,1366,1280): entries=[r for r in rows if r['width']==width] panel_width=1040 canvas=Image.new('RGB',(panel_width*2,4*164),(35,36,40)) draw=ImageDraw.Draw(canvas) for index,r in enumerate(entries): for column,side in enumerate(('sample','actual')): x=column*panel_width+10;y=index*164+8;m=r[side] draw.text((x,y),f"{width} / {r['theme']} / {side} | head {m['head']['width']}x{m['head']['height']} | input {m['search']['width']} | file {m['file']['width']}",fill='white') im=Image.open(out/f"{width}-{r['theme']}-{side}.png") for key,dy in (('head',26),('box',90)): box=m[key];left=int(box['x']);top=int(box['y']);right=round(box['x']+box['width']);bottom=round(box['y']+box['height']) canvas.paste(im.crop((left,top,right,bottom)),(x,y+dy)) canvas.save(out/f'compare-{width}.png')