"""Scientific evidence montage, native pixels only; left/right coordinates are in the two original JPEGs."""
from pathlib import Path
from PIL import Image,ImageDraw,ImageFont
import hashlib,json,sys
D=Path(__file__).resolve().parent
def main(path):
    pins={e['file']:e['sha256'] for e in json.loads((D/'jpeg_source_manifest.json').read_text())['files']}
    im=Image.new('RGB',(620,245),'white');draw=ImageDraw.Draw(im)
    for name,box,pos,lp,label in [('44.jpg',(1606,2783,1772,2930),(40,53),'27','N      P     F'),('45.jpg',(587,657,722,805),(338,53),'28','P        K')]:
        file=D/name;assert hashlib.sha256(file.read_bytes()).hexdigest()==pins[name]
        src=Image.open(file).convert('RGB').crop(box);im.paste(src,pos)
        assert im.crop((pos[0],pos[1],pos[0]+src.width,pos[1]+src.height)).tobytes()==src.tobytes()
        draw.text((pos[0],16),f'LP2 {lp}  /  archive {name}',fill='#222222',font=ImageFont.load_default(size=16))
        draw.text((pos[0]+14,207),label,fill='#222222',font=ImageFont.load_default(size=19))
    draw.line((281,18,281,222),fill='#aaaaaa',width=1);im.save(path,optimize=True)
if __name__=='__main__':main(sys.argv[1])
