Taionis image-PPT · 太元 图片转可编辑 PPT
You compose the figure; local scripts do everything else. describe.py and probe.py measure the image, ppt_session.py turns each SVG fragment into native slide objects in a .pptx, and compare.py scores a rendered preview against the reference. No external recognition API, key or upload is involved, and no script claims to have recognised the image.
Conventions (all agents)
SKILL_DIRmeans the folder containing this file. Use absolute paths in every command; do not rely on the working directory persisting between calls.- Run one short command per step. Every command prints one JSON object. Check
"ok", and onfalseread"error"(and"status") before doing anything else. - Write fragments and helper scripts to a work folder you create (e.g.
<out>/work), never insideSKILL_DIR.
Step 0: which app, and can you see the image?
- Ask the user which app to use before the first drawing of each new task, unless they already named one:
1. Microsoft PowerPoint,2. WPS. Map 1 →--app powerpoint, 2 →--app wps.startwithout--appreturnsneeds_app_selectionand creates nothing. Never pick for the user, and never switch apps silently. - If your model can view images: look at the image, and still measure with
probe.py; eyeballed coordinates and colours are the main source of error. - If you cannot view images (text-only model, or the image only arrives as a path): do not guess and do not claim to have looked. Run
python3 SKILL_DIR/scripts/describe.py <image> --out-dir <out>/describeand read<out>/describe/report.md. It lists the canvas, the palette, and every OCR'd label with its box, baseline, size, colour and orientation. It also lists rectangles, discs, lines, outlines, and heatmap regions with a ready-madeprobecommand. Tell the user you are working from a measured description, and ask about anything the report cannot settle.
How it shows up in the app
The result is a real .pptx file in the session folder, so it is the same in PowerPoint and WPS on macOS, Windows or Linux.
- PowerPoint on macOS:
startopens the deck, and everyappend-svg/updatecloses and reopens only this deck (matched by its full path). The slide therefore grows panel by panel while you work. - WPS, and PowerPoint elsewhere: the deck opens once, at
finish.
The deck is written by the script and is not opened for editing while you work, so the user's own documents are never touched. With --input-pptx, the original deck is copied, never modified: the figure goes onto --slide-index N (1-based), or onto a new blank slide when the index is 0.
Requirements
- Python 3.9+ with
python-pptx, Pillow, numpy, scipy (pip install -r SKILL_DIR/requirements.txt;install.shdoes this). - PowerPoint or WPS to open the result. For previews used by
compare.py: LibreOffice (any OS) or macOS Quick Look. - Local OCR for text-only models: macOS Vision via
scripts/ocr.swift, which needs the Xcode Command Line Tools (xcode-select --install). It runs offline. - Run
python3 SKILL_DIR/scripts/ppt_session.py doctorfirst. On macOS the first refresh may ask whether the terminal may control PowerPoint; the user must click Allow. Never click permission dialogs yourself.
Workflow
- Measure each region with
probe.py:--box X Y W H --colors 6: exact colours;--grid R C: heatmap cells--lines: frames and axes;--find "#hex": dots, bars and boxes--at X Y: a single colour;--crop out.png --zoom 3: an upscaled crop (only useful with vision) Coordinates are image pixels, origin top-left, y down.
- Start:
python3 SKILL_DIR/scripts/ppt_session.py start --output-root <out> --view-box 0 0 <W> <H> --app <powerpoint|wps> [--slide-size fit|16:9|4:3] [--input-pptx deck.pptx --slide-index N]fit(default) sizes the slide to the figure.16:9/4:3fit the figure into a standard slide with a small margin. - Author fragments with figkit and append them in paint order, one panel at a time:
python3 SKILL_DIR/scripts/ppt_session.py append-svg --session <session_dir> --svg <fragment.svg>Write a small Python script that doessys.path.insert(0, 'SKILL_DIR/scripts')and importsfigkit(Fragment,header,gray_title,tube; methodsrect/circle/ellipse/path/line/polygon/text/rich/arrow/block_arrow/heat/bars/stacked_hbars/scatter/axes/pie/wedge/arc/chord_ribbon/flow_band/legend/gradient). Give stable ids to objects you may need to fix.SKILL_DIR/examples/cellchat/build_fragments.pyis a full example.data-ai-layerand<g id>become named groups on the slide. - Check:
python3 SKILL_DIR/scripts/ppt_session.py export --session <session_dir> --png <out>/render.pngThis renders only the figure area, with LibreOffice or Quick Look. Then compare:python3 SKILL_DIR/scripts/compare.py --reference <image> --render <out>/render.png --out-dir <out>/cmp --svg <fragments...>With vision, open the crops of the worst regions. Without vision, rundescribe.pyonrender.pngtoo and compare the two reports. - Fix in place: resend only the wrong objects, with the same ids, using
ppt_session.py update --session <session_dir> --svg fix.svg. Stacking order is kept, and new ids are added. Delete objects withppt_session.py remove --session <session_dir> --ids a b. Repeat steps 4–5; do not start over for local mistakes. - Finish:
python3 SKILL_DIR/scripts/ppt_session.py finish --session <session_dir>writes the final deck and opens it in the chosen app. Report the deck path. The user can Save As from the app to keep it elsewhere.
For a finished master SVG, the one-shot alternative is ppt_session.py draw --output-root <out> --svg master.svg --app <powerpoint|wps>.
Read SKILL_DIR/references/svg-contract.md before authoring fragments.
Rules
- Everything stays editable: freeforms keep their Bézier points (Edit Points works), holes are real (subpaths of one freeform), text stays text in text boxes, and sub/superscripts are real baseline offsets. Never paste the diagram as a picture, and never hide a hole with a white shape.
- Photographs, microscopy and measured data that would require inventing values stay as real pixels: crop them from the reference into the work folder and place them with
<image href="crop.png">. Draw only their annotations as editable shapes, and tell the user. - Chinese/Japanese/Korean text gets an East Asian font (PingFang SC on macOS, Microsoft YaHei on Windows; override with
--cjk-font). - Unsupported SVG (markers,
<use>, masks, filters, clip-path, textPath, patterns, data-URI images) is rejected before anything changes; expand it into plain geometry. - Never modify the input deck or any other open presentation. Never quit or close the user's apps or documents. Only the session's own deck may be closed and reopened for preview.
- Report honestly: a rendered PNG is a preview (LibreOffice / Quick Look can differ slightly from PowerPoint and WPS). Text box widths are estimates, so check labels after opening. A text-only model must say its slide is based on measurements rather than on seeing the image.