inspect_pptx_picture_layouts.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from __future__ import annotations
  2. import json
  3. import sys
  4. from pathlib import Path
  5. from pptx import Presentation
  6. from pptx.enum.shapes import MSO_SHAPE_TYPE
  7. MANIFEST = Path(sys.argv[1] if len(sys.argv) > 1 else "artifacts/music-template-extraction/review/manifest.json")
  8. TARGETS = set(sys.argv[2:] or ["candidate-05", "candidate-20", "candidate-26", "candidate-30", "candidate-31", "candidate-33"])
  9. def main() -> None:
  10. items = json.loads(MANIFEST.read_text(encoding="utf-8"))["items"]
  11. for item in items:
  12. if item["id"] not in TARGETS:
  13. continue
  14. deck = Presentation(item["source"])
  15. print(f"\n{item['id']} {item['name']}")
  16. for sample in item["samples"]:
  17. number = int(Path(sample).stem.split("-")[1])
  18. slide = deck.slides[number - 1]
  19. print(f" slide={number}")
  20. for index, shape in enumerate(slide.shapes):
  21. if shape.shape_type != MSO_SHAPE_TYPE.PICTURE:
  22. continue
  23. left = shape.left / deck.slide_width
  24. top = shape.top / deck.slide_height
  25. width = shape.width / deck.slide_width
  26. height = shape.height / deck.slide_height
  27. print(f" picture={index:02d} box=({left:.3f},{top:.3f},{width:.3f},{height:.3f}) area={width * height:.3f}")
  28. if __name__ == "__main__":
  29. main()