Taionis image-AI · 太元 图片转 Illustrator
You compose the figure; local scripts do everything else. describe.py and probe.py measure the image, ai_session.py turns each SVG fragment into native Illustrator objects through AppleScript do javascript, and compare.py scores the export 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_DIRbelow means 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 (start, one fragment, export…). Each
append-svgof a normal panel takes seconds; if your tool has a command timeout, keep fragments to roughly 300 objects or fewer. - Every command prints one JSON object. Check
"ok"before continuing; onfalse, read"error"and fix the cause instead of retrying blindly. - Write fragments and helper scripts to a work folder you create (for example
<out>/work), never insideSKILL_DIR.
Requirements
- macOS + Adobe Illustrator (developed on Illustrator 2026 / 30.1.0),
python3with Pillow, numpy, scipy (pip install -r SKILL_DIR/requirements.txt;install.shdoes this). - Local OCR for text-only models uses macOS Vision via
scripts/ocr.swift(needs Xcode Command Line Tools:xcode-select --install). It runs offline. - First run
python3 SKILL_DIR/scripts/ai_session.py doctor. It reports the Illustrator version, open documents and missing fonts. The first AppleScript call makes macOS ask whether the terminal/agent may control Illustrator; the user must click Allow (error -1743 → System Settings › Privacy & Security › Automation). Never try to grant permissions or click dialogs yourself.
Step 0 — can you see the image?
- If your model can view images (you can actually see the attached picture): look at it, and still use the measurements below; eyeballed coordinates and colours are the main source of error.
- If you cannot view images (text-only model, or the image arrives only as a file path): do not guess and do not claim to have looked. Build your understanding from the report:
python3 SKILL_DIR/scripts/describe.py <image> --out-dir <out>/describeRead<out>/describe/report.md. It gives the canvas size, palette, every OCR'd label with box, baseline, estimated size, colour and orientation, filled rectangles, discs, lines, outlines, and dense regions (heatmaps) with a ready-madeprobecommand. Tell the user that you are working from a measured description, and ask them about anything the report cannot settle (for example, which shapes an arrow connects). If OCR is unavailable the report says so; ask the user to transcribe the labels.
Workflow
- Measure. Use
probe.pyon each region you are about to draw:--box X Y W H --colors 6: exact palette colours;--grid R C: per-cell heatmap colours--lines: frame borders, axes, grid lines;--find "#hex" [--tol 40]: positions of dots, bars, boxes in that colour--at X Y: one colour;--box … --crop out.png --zoom 3: an upscaled crop (only useful if you can view images) All coordinates are image pixels, origin top-left, y down.
- Start a session. This opens a new blank document; other open documents are never touched:
python3 SKILL_DIR/scripts/ai_session.py start --output-root <out> --view-box 0 0 <W> <H> [--scale 1] [--color-mode rgb|cmyk]It returnssession_dir. - Author fragments with figkit and append them in paint order (back to front), one panel at a time:
python3 SKILL_DIR/scripts/ai_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. Each fragment is a complete<svg>with the session viewBox;data-ai-layeron its top<g>names the Illustrator layer. - Check. Export a preview (this does not save the .ai):
python3 SKILL_DIR/scripts/ai_session.py export --session <session_dir> --png <out>/render.pngThen compare it with the reference:python3 SKILL_DIR/scripts/compare.py --reference <image> --render <out>/render.png --out-dir <out>/cmp --svg <fragments...>compare.jsonranks panels worst-first, with scores and hot boxes. With vision, open the crops it lists. Without vision, rundescribe.pyonrender.pngas well and compare the two reports (missing labels, shifted boxes, wrong colours). - Fix in place. Regenerate only the wrong objects, with the same ids, into a fix fragment:
python3 SKILL_DIR/scripts/ai_session.py update --session <session_dir> --svg fix.svgThis keeps their stacking position; new ids are added. To delete objects:… remove --session <session_dir> --ids a b. Only objects this session drew can be removed. Repeat steps 4–5 until the worst regions match. Do not restart the whole drawing for local mistakes. - Finish.
python3 SKILL_DIR/scripts/ai_session.py finish --session <session_dir> [--export-png out.png]returnscompleted_unsaved, and the drawing stays open for the user to save. Pass--save-ai path.aionly when the user explicitly asked to save.
For a finished master SVG, the one-shot alternative is ai_session.py draw --output-root <out> --svg master.svg.
Read SKILL_DIR/references/svg-contract.md before authoring fragments.
Rules
- Everything stays editable: exact cubic Béziers, strokes stay strokes, holes are real compound paths, text stays live text (sub/superscripts via
rich). Never rasterize a diagram or hide a hole with white paint. - Photographs, microscopy and measured data that would require inventing values are kept as real pixels: crop them from the reference into the work folder and place them with
<image href="crop.png">(placed + embedded). Draw only their annotations as vectors, and tell the user. - Chinese/Japanese/Korean text in a Latin font is switched to PingFang SC automatically. Missing fonts are reported in
missing_fontsand replaced by Arial. - Unsupported SVG features (markers,
<use>, masks, filters, clip-path, textPath, patterns, data-URI images) are rejected before anything is drawn; expand them into plain geometry. - Saving is manual: no Save/Save As at start, during, on completion or on failure. On failure partial work stays visible and unsaved; report how far it got.
- If Illustrator times out, a dialog is probably open there. Ask the user to close it; do not retry in a loop.
- Report honestly: an SVG, a PNG export or a compare score is not a saved
.aifile, a good score does not replace checking, and a text-only model must say its redraw is based on measurements rather than on seeing the image.