from PIL import Image, ImageDraw, ImageFont
from pathlib import Path
import re,textwrap
root=Path(__file__).parent/'run-20261123-041729'
for side in ['before','after']:
 text=(root/(side+'.txt')).read_text()
 text=re.sub(r'\[[^\n]* INFO [^\n]*Running database migrations\n\[[^\n]*Migrations ran successfully \{\n.*?\n}\n','[Database migrations completed successfully]\n',text,flags=re.S)
 text=re.sub(r'    at .*\n','',text)
 lines=[]
 for line in text.splitlines():
  lines.extend(textwrap.wrap(line,100,replace_whitespace=False,drop_whitespace=False) or [''])
 font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',17)
 im=Image.new('RGB',(1120,len(lines)*25+48),'#10151d');d=ImageDraw.Draw(im)
 for i,l in enumerate(lines):d.text((24,24+i*25),l,font=font,fill='#e3e9ef')
 im.save(root/(side+'.png'))
