38 lines
2.0 KiB
Python
38 lines
2.0 KiB
Python
from pathlib import Path
|
||
import json
|
||
import fitz
|
||
from PIL import Image, ImageOps, ImageDraw
|
||
root=Path('/Users/adolforeyna/brain/exports')
|
||
out=root/'emi_astra_previews';out.mkdir(exist_ok=True)
|
||
doc=fitz.open(root/'emi_astra_family_that_remains.pdf')
|
||
results=[]
|
||
for i,p in enumerate(doc):
|
||
text=p.get_text().strip(); r=p.rect
|
||
bounds=[]
|
||
for block in p.get_text('dict')['blocks']:
|
||
for line in block.get('lines',[]):
|
||
for span in line['spans']:
|
||
b=fitz.Rect(span['bbox'])
|
||
if not r.contains(b):bounds.append({'text':span['text'],'bbox':list(b)})
|
||
results.append({'slide':i+1,'width_pt':r.width,'height_pt':r.height,'ratio':r.width/r.height,'text_characters':len(text),'text_outside_page':bounds})
|
||
p.get_pixmap(matrix=fitz.Matrix(1,1),alpha=False).save(out/f'emi_astra_slide_{i+1:02}.png')
|
||
(out/f'emi_astra_slide_{i+1:02}.txt').write_text(text)
|
||
assert len(doc)==11, len(doc)
|
||
assert all(abs(x['ratio']-16/9)<.001 for x in results)
|
||
assert all(x['text_characters']>100 for x in results)
|
||
assert not any(x['text_outside_page'] for x in results)
|
||
dom=json.loads((root/'emi_astra_dom_bounds.json').read_text())
|
||
assert len(dom)==11 and all(not s['overflow'] for s in dom)
|
||
full_text=' '.join(p.get_text() for p in doc)
|
||
for term in ['Matthew 28:18–20','ethnos','Romans 15:20','Chiapas','San Luis','Chile','Venezuela','4 / EXCHANGE','5 / PRAY','6 / STRENGTHEN CHILE','7 / FOCUS']:
|
||
assert term.casefold() in full_text.casefold(), f'Missing source detail: {term}'
|
||
w,h=768,432
|
||
sheet=Image.new('RGB',(w*2,(h+44)*6),'#dce1e6');draw=ImageDraw.Draw(sheet)
|
||
for i in range(len(doc)):
|
||
im=Image.open(out/f'emi_astra_slide_{i+1:02}.png').convert('RGB').resize((w,h))
|
||
x=(i%2)*w;y=(i//2)*(h+44)
|
||
sheet.paste(im,(x,y));draw.text((x+16,y+h+12),f'SLIDE {i+1:02}',fill='#172b45')
|
||
sheet.save(root/'emi_astra_contact_sheet.jpg',quality=94)
|
||
(root/'emi_astra_verification.json').write_text(json.dumps({'passed':True,'page_count':len(doc),'slides':results},indent=2))
|
||
print(json.dumps({'passed':True,'page_count':len(doc),'slides':results},indent=2))
|