Use when users want XiaoBei skill / xiaobei-skill / 小北在读研 style academic image-to-VBA reconstruction: convert academic figures, scientific diagrams, slides, screenshots, or other images into VBA, Office drawing code, PowerPoint/Excel/Word shapes, editable shape reconstruction, 1:1 recreation, pixel-like approximation, or hybrid editable Office shape reconstruction.
npx skills add https://github.com/xiao24bei/xiaobei-skill --skill xiaobei-skill-image-to-vba
小北在读研出品的 academic image-to-vba reconstruction skill. The workflow focuses on editable Office Shapes first, with carefully labeled raster crops only when complex scientific artwork should be preserved.
All analysis, manifest tables, self-check reports, run reports, and conversational responses produced by this skill MUST be written in Simplified Chinese (简体中文). This includes:
' 标题区域背景),便于用户后续维护。仅以下内容保留英文原样,不要翻译:
Sub、Shapes.AddShape、Fill.ForeColor.RGB 等)。AITVBA_ 与脚本路径、文件名。RGB(...) 调用本身。如果用户在对话里明确要求换成英文或其它语言,则按用户指定的语言输出,但 manifest 字段名仍保留英文 key 以便机器解析。
Convert a reference image into a complete, runnable Office VBA macro that reconstructs the visual using editable Shapes, TextBoxes, Lines, Freeforms, fills, gradients, transparency, shadows, and ZOrder. When the image contains complex, distinctive graphic elements that would become noisy or low-value if rebuilt as hundreds of shapes, preserve those elements as cropped local image assets and reconstruct the surrounding structure with editable VBA Shapes. The core loop is: image -> environment detection -> visual decomposition -> editable-vs-preserved element plan -> Office coordinate model -> VBA Shapes code and cropped assets -> run or prepare the macro in the available presentation app -> self-check -> iterative correction.
Prefer editable Office Shapes for structure, labels, arrows, boxes, chart scaffolds, and readable text. Preserve complex graphic elements only as local cropped assets when that improves fidelity and keeps the VBA maintainable. Do not embed the full source image as a shortcut unless the user explicitly permits it or chooses the background-image-assisted option for complex photos. A PNG/JPEG/PDF preview is never the final deliverable for this skill; it is only allowed as a diagnostic screenshot after an editable Office reconstruction has been produced or attempted.
When the user provides an image and asks for reconstruction, the default target is a presentation deck unless another Office host is explicit. Prefer Microsoft PowerPoint automation when available, but support WPS users and no-local-office users with a truthful fallback path. The agent must produce:
.bas / .pptx / .pptm files are located.Do not satisfy an image-to-VBA request by generating only a PNG image, raster preview, static screenshot, or visual mockup. If a preview image is useful, create it only in addition to the editable VBA/PPT deliverables.
Use hybrid preservation when any of the hard triggers below fire. Do not rely on subjective judgment about whether the result "looks cluttered" — model self-assessment is biased toward editable reconstruction, which causes complex artwork to be redrawn poorly. The goal is to preserve high-complexity artwork while keeping the diagram's editable structure editable.
Hard preservation triggers (hit any one → the element MUST be preserved as a raster crop):
If none of the triggers fire, treat the element as editable. If a trigger fires but the user demanded "all editable", explain the fidelity tradeoff first and get permission before redrawing.
Classify every visible element into one of three buckets:
Hybrid rules:
AITVBA_Raster_Microscope_01.assets/ subdirectory.保留元素出现"裁错 / 变形 / 缩放比例不对"是 hybrid 模式最常见的失败。下面这套契约是硬性的,违反任何一条都视为本轮 render-verify 不通过,必须回到 manifest 修正。
scripts/crop_preserved_elements.py 时,传入的坐标必须与 manifest 中该元素的 bbox_px 完全一致(整数像素)。bbox_px 扩到包含阴影的范围,而不是裁的时候临时加。Shapes.AddPicture 后,只能用 ratio-safe 缩放:已知裁剪图原始像素宽高 cw_px, ch_px,目标插入区域宽高 tw_pt, th_pt,则:s = min(tw_pt / cw_px, ch_px > 0 ? th_pt / ch_px : 1)cw_px * s,高 = ch_px * sWidth = X : Height = Y 把图片强行拉到 manifest 的目标尺寸,除非目标尺寸恰好与裁剪图等比。一旦目标 bbox 与裁剪源比例不一致,要么调整目标 bbox 使之与源等比,要么在目标区域内居中留白。AddPicture 之后再设置 LockAspectRatio = msoFalse 然后独立改宽高。bbox_px 既描述源图坐标,也决定目标 bbox 的宽高比。bbox_px 比例偏差超过 ±2%,说明裁剪坐标错了,必须重新裁,而不是在插入时拉伸去"对齐"。Rotation = 0,FlipH = msoFalse,FlipV = msoFalse。除非原图本来就是斜的,且 manifest 里该行显式给出了 rotation_deg 字段,否则不许动。scale / offset_x_pt / offset_y_pt 公式把 bbox_px 的 (x, y) 转成插入点 (Left, Top)。assets/<id>_<语义短名>.png,例如 assets/R03_microscope_left.png。在第 6 节 Mandatory Self-Checks 的"Preservation check"基础上,每一轮 render-verify 都额外运行下面四问,任何一问回答不出"是",该元素就不算合格:
AddPicture 之后的 Shape.Width / Shape.Height 比值与裁剪图原始比值之差 < 2% 吗?不达标时,优先调整 manifest 的 bbox_px 与 crop_path,而不是在 VBA 里硬拉尺寸。
Before trying to materialize a deck, identify the user's local runtime. Use scripts/detect_office_environment.py when local shell access is available; otherwise infer from the user's stated OS and installed office suite.
Choose the delivery path in this order:
.bas, run scripts/vba_lint.py, then try scripts/run_powerpoint_vba_windows.ps1. Report if PowerPoint Trust Center blocks VBA import..bas, run scripts/vba_lint.py, then try scripts/run_powerpoint_vba_macos.py. Report if AppleScript automation or Office macro security blocks execution..bas file. Do not assume automatic VBA import/run is available. If WPS can be opened locally, open it and provide WPS-specific manual import/run steps. If WPS macro support is absent or unverified, say that plainly..bas VBA source. When feasible, also generate an editable .pptx fallback from the same shape plan, clearly labeled as a non-VBA fallback. Do not substitute a PNG as the final output.Use WPS-compatible mode when WPS is the only available app:
TextFrame2 behavior, gradient stops, and macro security settings unless verified locally..bas, .pptx, .pptm) rather than WPS-only formats unless the user asks otherwise.Identify the target Office host:
Ask a concise clarification only when the target host materially changes the solution and cannot be inferred. Otherwise proceed with the default presentation target, detect the available runtime, and attempt the best supported create/open path.
Classify the source image:
Inspect the image before coding. Record:
For detailed pattern examples, load references/vba-shape-patterns.md only when needed.
Before writing any VBA, produce an explicit element manifest. This step is mandatory — do not skip to coordinate modeling or code generation without it. Skipping the manifest is the root cause of three frequent failures: missed preservation, drifted layout, and arrows pointing to wrong endpoints.
Output the manifest as a Markdown table or JSON list with these fields per element:
id: stable short id, for example E01, R01, L01. Use E* for editable, R* for preserved raster, L* for lines/arrows/connectors, B* for background.type: rect, ellipse, textbox, arrow, line, freeform, group, raster_crop, background, etc.bucket: editable, preserved, or background. Apply the hard preservation triggers from "Hybrid Preservation Mode" — do not guess.bbox_px: (x, y, w, h) in source-image pixels. Required for every element except pure connectors. Estimate visually but commit to numbers; do not write ? or "approx".style: fill color (hex or RGB), stroke color, stroke width, font size, font weight, opacity, shadow, gradient endpoints, etc. Use null only when the element has no such property.text: exact text content for textboxes; null otherwise. Mark uncertain readings with a trailing (?).endpoints: for arrows/lines/connectors only. Mandatory and strict. Format must be from:(x1_px,y1_px) -> to:(x2_px,y2_px) [anchor:<id>.<side>=<id>.<side>]. Both absolute pixel coordinates AND the semantic anchor (which element's which side) are required when the line connects two elements. Reasons:via:(x,y);(x,y) 字段补充中间拐点像素坐标。anchor:free。Shapes.AddConnector 并 BeginConnect / EndConnect 到具体形状,而不是用绝对坐标画一根 AddLine。这样箭头会随被连接元素位置自动跟随,不会乱指。z_order: integer, lower draws first.preserve_reason: required when bucket = preserved. State which hard trigger fired.crop_path: required when bucket = preserved. Use assets/<id>_<short_name>.png.Example minimal row:
| id | type | bucket | bbox_px | style | text | endpoints | z | preserve_reason | crop_path |
|-----|-----------|-----------|--------------------|-----------------------------|------------|------------------------------|---|-----------------|----------------------------|
| E01 | rect | editable | 120,80,200,60 | fill=#FF8800,stroke=#333,2pt| "Input" | — | 2 | — | — |
| R01 | raster | preserved | 400,200,180,180 | — | — | — | 1 | microscopy image| assets/R01_microscopy.png |
| L01 | arrow | editable | — | stroke=#000,2pt,arrow_end | — | from:E01.right -> to:R01.left| 3 | — | — |
Manifest gate: do not generate VBA until every visible element appears in the manifest. The number of rows in the manifest is the lower bound on the number of Shapes the macro will create (preserved elements count as one AddPicture each). If a region of the image has no manifest row, you have not parsed that region — go back to step 2.
Model the image in Office points by default.
960 pt as the long side unless the user requests a specific slide size.offset_x_pt / offset_y_pt; do not stretch the image independently on X and Y.scale = min(target_width_pt / image_width_px, target_height_pt / image_height_px)offset_x_pt = (target_width_pt - image_width_px * scale) / 2offset_y_pt = (target_height_pt - image_height_px * scale) / 2x_pt = offset_x_pt + x_px * scaley_pt = offset_y_pt + y_px * scalew_pt = w_px * scaleh_pt = h_px * scalex_pt = x_px * target_width_pt / image_width_pxy_pt = y_px * target_height_pt / image_height_pxw_pt = w_px * target_width_pt / image_width_pxh_pt = h_px * target_height_pt / image_height_pxscripts/coordinate_helper.py to calculate scale values and examples.Generate a complete runnable VBA macro, not a fragment. For the default presentation target, also save the macro as a .bas or .vba file in the working directory so it can be run or pasted without copying from chat.
Use a two-pass generation strategy. The two-pass split exists because layout errors are cheapest to catch before any styling is applied; do not skip Pass 1 to save time.
id printed inside as a label. No fills, no gradients, no shadows, no fonts beyond a default 10pt. The skeleton's only job is to confirm bbox positions, sizes, and arrow endpoints match the source. If the skeleton is visibly wrong, fix the manifest first, not the styling.Shapes.AddPicture.You may emit both passes as two separate Sub procedures inside the same .bas file (for example Sub BuildSkeleton() and Sub BuildFinal()), so the user can run the skeleton first and the styled version second without regenerating code.
The macro must include:
Sub ... End Sub wrapper.Shapes.AddPicture code for each preserved local crop in hybrid mode, with LinkToFile:=msoFalse and SaveWithDocument:=msoTrue where the host supports it.shp.Name = "Header_Background".RGB(...) or small helper functions.ZOrder or creation order.AITVBA_ for shape names and cleanup.Use Office APIs conservatively:
Shapes.AddShape, Shapes.AddTextbox, Shapes.AddLine, Shapes.BuildFreeform, FreeformBuilder.Shapes.AddPicture for preserved raster crops in hybrid mode.Fill.ForeColor.RGB, Fill.Transparency, Line.ForeColor.RGB, Line.Weight.TextFrame / TextFrame2 font settings as appropriate for the host.Shadow, GradientStops, PresetGradient, or layered translucent shapes to approximate effects.For the default presentation target, after generating the VBA:
.bas or .vba file.scripts/crop_preserved_elements.py when crop coordinates are known.scripts/vba_lint.py against the generated VBA file.scripts/detect_office_environment.py when possible.scripts/run_powerpoint_vba_windows.ps1.scripts/run_powerpoint_vba_macos.py when applicable..bas path, and give WPS-specific manual run steps.The final answer must not imply that a PNG preview is the editable deliverable. It must distinguish between source image, preview screenshot, VBA source file, editable deck file, WPS-compatible file, and any non-VBA PPTX fallback.
Perform these self-check rounds before final output:
AddPicture placement, shape name, and reason for preservation.scripts/vba_lint.py as a lightweight smoke check when code is available as a file or can be copied into a temporary file; do not overstate it as a full VBA compiler.每一轮的固定动作:
Slide.Export;macOS 用 AppleScript / PowerPoint 导出)。scripts/compare_images.py 与原图比对,输出整体 SSIM、整体像素差比例,以及差异最大的若干局部区域(按 bbox 列出)。通过条件(同时满足才能交付):
endpoints 字段对应的箭头在渲染图里目测连接到了正确的元素边界。迭代上限:最多 6 轮。每轮必须在最终报告里附一行"第 N 轮:SSIM=0.xx,最大差异区域=…,本轮修改了 …"。
终止策略:
报告语言:每轮的差异分析、区域定位、修改说明都用简体中文(遵循文件顶部 Output Language 规则)。
仅在本机确实无法跑宏时(无 Office、Trust Center 拦截、沙箱环境),才允许跳过该闭环并降级为标注清楚的"人工目测估计",且必须在报告中说明为什么没跑、用户在哪里能自行运行该闭环。
If a check finds a gap, revise the VBA before responding. Mention unresolved uncertainty only after revising what can be revised.
Use the structure in references/output-template.md:
Always include a short "How to run" section. Keep it host-specific and practical.
Do not promise perfect pixel-level reconstruction for complex photos, textures, real people, dense raster effects, or highly complex gradients. Explain that Office Shapes can approximate these but cannot fully reproduce raster detail.
Unless the user explicitly allows full-image insertion, do not place the original image on the slide/sheet/document and claim it is reconstructed. This restriction does not prohibit small local preserved crops in hybrid mode, as long as they are clearly labeled. If using a full background image is appropriate, label it clearly as the background-assisted option and keep editable overlays separate.
Never replace the editable deliverable with a PNG, screenshot, or generated raster image. A raster image may be used only for source analysis, validation, optional preview, or explicitly labeled local preserved elements in hybrid mode.
For "1:1" requests:
scripts/vba_lint.py: lightweight checks for generated VBA.scripts/detect_office_environment.py: detect likely Microsoft PowerPoint/WPS runtimes and recommend a materialization path.scripts/crop_preserved_elements.py: crop local preserved raster elements from the source image for hybrid reconstruction.scripts/run_powerpoint_vba_macos.py: attempt to run generated PowerPoint VBA through macOS PowerPoint automation and bring PowerPoint forward.scripts/run_powerpoint_vba_windows.ps1: attempt to import and run generated VBA through Windows Microsoft PowerPoint COM automation.scripts/compare_images.py: compare source image and rendered VBA screenshot.scripts/coordinate_helper.py: convert image pixels to Office point coordinates.references/vba-shape-patterns.md: common Office Shapes patterns.references/reconstruction-checklist.md: detailed review checklist.references/output-template.md: final response template.Take xiao24bei/xiaobei-skill-image-to-vba from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.