"""Cut the three load-bearing blocks out of the rebuilt page raster and wrap them in a single self-contained HTML so the page can be read as an image (never as the OCR text layer). Blocks come from graham-page.py's position map of journal page 84: THEOREM ~y 822 px (statement + its displayed formula) Barban and Vehov ~y 1543 px (display (5)) COROLLARY ~y 1924 px (statement + both cases) """ import base64 import io import sys from PIL import Image SRC = sys.argv[1] if len(sys.argv) > 1 else "p84.png" OUT = sys.argv[2] if len(sys.argv) > 2 else "graham-p84.html" BLOCKS = [ ("THEOREM + main term", 780, 1090), ("display (5): Barban and Vehov", 1500, 1720), ("COROLLARY, both cases", 1880, 2190), ] def data_uri(img): buf = io.BytesIO() img.save(buf, format="PNG") return "data:image/png;base64," + base64.b64encode(buf.getvalue()).decode() page = Image.open(SRC).convert("L") parts = [] for label, y0, y1 in BLOCKS: crop = page.crop((0, y0, page.width, y1)) crop = crop.resize((int(crop.width * 1.7), int(crop.height * 1.7)), Image.LANCZOS) parts.append( f'
{label}  ·  raster rows {y0}-{y1} of {page.width}x{page.height}' f'
' ) html = f""" Graham 1978, J. Number Theory 10, 83-94 — page 84 raster {''.join(parts)} """ with open(OUT, "w", encoding="utf-8") as fh: fh.write(html) print(f"wrote {OUT} ({len(html)} bytes), blocks={len(BLOCKS)}")