component
RC0402FR-0733KL - YAGEO
Public Made by Adomby adom
Thick film chip resistor 33 kOhm +/-1 %, 1/16 W, 50 V, 0402 (1005 metric)
main
"""Crop the cited datasheet figures into docs/figures/ (rendered at 150 dpi with pdftoppm).
usage: figures.py <slug>
"""
import sys, os, json, subprocess, hashlib
from PIL import Image
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import parts
ROOT = "/tmp/claude-1001/esc3"
slug = sys.argv[1]
P = next(p for p in parts.PARTS if p["slug"] == slug)
OUT = os.path.join(ROOT, "pages", slug, "docs", "figures"); os.makedirs(OUT, exist_ok=True)
pdfs = {"ds": os.path.join(ROOT, "dl", P["ds"]["local"]), "mount": os.path.join(ROOT, "dl", parts.MOUNT["local"])}
cache = os.path.join(ROOT, "work", "fig150"); os.makedirs(cache, exist_ok=True)
figs = [parts.FIG_DIM, parts.FIG_ELEC, parts.FIG_MARK, parts.FIG_VOLT, parts.FIG_PACK, parts.FIG_STO, parts.FIG_LAND]
rec = []
for name, doc, page, box, caption in figs:
png = os.path.join(cache, f"{doc}-{page}.png")
if not os.path.exists(png):
subprocess.run(["pdftoppm", "-r", "150", "-png", "-singlefile", "-f", str(page), "-l", str(page), pdfs[doc], png[:-4]], check=True)
im = Image.open(png).convert("RGB")
b = [int(round(v * 1.5)) for v in box]
out = os.path.join(OUT, name); im.crop(b).save(out, optimize=True)
rec.append({"file": f"docs/figures/{name}", "document": P["ds"]["title"] if doc == "ds" else parts.MOUNT["title"],
"page": page, "crop_px_at_150dpi": b, "caption": caption,
"sha256": hashlib.sha256(open(out, "rb").read()).hexdigest()})
json.dump(rec, open(os.path.join(OUT, "figures.json"), "w"), indent=1)
print("figures", len(rec))