Spaces:
Paused
Paused
File size: 2,195 Bytes
dac3297 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | """
Visualize all 13 gold boxes overlaid on the full cellar page.
"""
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
import fitz
ROOT = Path(__file__).resolve().parent.parent
PDF_PATH = ROOT / "raw_pdfs" / "355 E 86th St Mechanical 100% CD Set_flattened.pdf"
# Verified gold boxes
GOLD = [
{"tag": "AC-P", "x": 7050, "y": 1300, "w": 500, "h": 550},
{"tag": "AC-S", "x": 3970, "y": 2200, "w": 500, "h": 500},
{"tag": "AC-Q", "x": 2530, "y": 2800, "w": 500, "h": 500},
{"tag": "AC-P", "x": 2530, "y": 3650, "w": 900, "h": 650},
{"tag": "AC-P", "x": 2530, "y": 4600, "w": 900, "h": 650},
{"tag": "AC-P", "x": 5750, "y": 4450, "w": 700, "h": 500},
{"tag": "AC-T", "x": 1800, "y": 6050, "w": 500, "h": 500},
{"tag": "AC-T", "x": 3300, "y": 7220, "w": 500, "h": 500},
{"tag": "AC-U", "x": 6600, "y": 6950, "w": 500, "h": 500},
{"tag": "AC-U", "x": 9050, "y": 7310, "w": 500, "h": 500},
{"tag": "AC-T", "x": 8300, "y": 5700, "w": 500, "h": 500},
{"tag": "AC-T", "x": 9600, "y": 6200, "w": 500, "h": 500},
{"tag": "unit", "x": 8200, "y": 400, "w": 600, "h": 600},
]
def render_page(pdf_path: Path, page_num: int, dpi: int) -> Image.Image:
doc = fitz.open(pdf_path)
page = doc.load_page(page_num - 1)
pix = page.get_pixmap(matrix=fitz.Matrix(dpi / 72, dpi / 72), alpha=False)
return Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
# Render full cellar at 300 DPI
print("Rendering full cellar page...")
cellar = render_page(PDF_PATH, 2, 300)
draw = ImageDraw.Draw(cellar)
font = ImageFont.load_default()
# Draw all 13 gold boxes
for idx, box in enumerate(GOLD, 1):
x1 = box["x"]
y1 = box["y"]
x2 = box["x"] + box["w"]
y2 = box["y"] + box["h"]
# Draw box
draw.rectangle([x1, y1, x2, y2], outline=(0, 255, 0), width=3)
# Label
label = f"{idx}. {box['tag']}"
draw.text((x1, y1 - 20), label, fill=(0, 255, 0), font=font)
# Save
out_path = Path(__file__).resolve().parent / "gold_boxes_on_cellar.jpg"
cellar.save(out_path, quality=85)
print(f"Saved: {out_path}")
print(f"Page size: {cellar.width}x{cellar.height}")
print(f"Gold boxes: {len(GOLD)}")
|