from PIL import Image,ImageDraw,ImageFont
import pathlib,sys,textwrap,time,hashlib
run=pathlib.Path(sys.argv[1]); font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',18)
for side in ['before','after']:
    lines=[]
    for line in (run/f'{side}.txt').read_text().splitlines():
        lines.extend(textwrap.wrap(line,110,replace_whitespace=False,drop_whitespace=False) or [''])
    def capture():
        im=Image.new('RGB',(1240,50+len(lines)*26),'#111827'); d=ImageDraw.Draw(im)
        for i,line in enumerate(lines): d.text((24,24+i*26),line,font=font,fill='#e5e7eb')
        return im
    a=capture(); time.sleep(.5); b=capture()
    assert a.tobytes()==b.tobytes()
    b.save(run/f'{side}.png')
