from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
import re, textwrap
root = Path(__file__).parent
for side, sha in [('base','7cb8305e3a'), ('head','1c77364714')]:
    for scope in ['one','two']:
        stem=f'{side}-{scope}'
        snap=(root/f'{stem}.txt').read_text()
        label=re.search(r'\[button\] "(Squash and merge[^\n]+)"',snap).group(1)
        image=Image.open(root/f'{stem}-b.png').convert('RGB')
        result=Image.new('RGB',(image.width,image.height+320),'#101827')
        result.paste(image,(0,0))
        draw=ImageDraw.Draw(result)
        font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',34)
        bold=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf',34)
        draw.text((35,image.height+20),f'{"Before" if side=="base" else "After"} · {sha} · Pixel 9 / Android 36',font=bold,fill='white')
        draw.text((35,image.height+75),'Captured Android accessibility button label:',font=font,fill='#a5b4fc')
        for i,line in enumerate(textwrap.wrap(label,width=49)):
            draw.text((35,image.height+130+i*45),line,font=font,fill='white')
        result.save(root/f'{stem}-evidence.png')
