Communitygithub.com

lz1159435992/sketch-to-drawio

Rebuild raster paper-figure sketches (GPT/hand-drawn) as native editable draw.io vector figures — agent skill with icon sourcing, sketch tracing/upscaling, and attribution/QC ledgers.

What is sketch-to-drawio?

This skill converts bitmap sketches (e.g., hand-drawn or GPT-generated figures) into fully editable draw.io vector diagrams, preserving layout, modules, and relationships while replacing raster elements with native draw.io shapes, editable text, and independent SVG icons. It follows a strict workflow: analyze the sketch, plan elements, redraw natively using draw.io XML, export previews, self-check for layout issues, and deliver attribution and quality-control (QC) ledgers. The skill prioritizes open-source SVG icons (Lucide, Iconify) and uses a cascading fallback from simple functional icons to complex illustrations, with an emphasis on style consistency and fidelity to the original sketch. It is designed for academic paper figures, enforces constraints like white backgrounds, low-saturation colors, and CJK font checks, and includes anti-hallucination guards to avoid fabricating details or icons. It leverages an external drawio-skill for XML syntax and headless export using xvfb-run.

Works with✓Claude Code✓Codex CLI~Cursor
npx skills add lz1159435992/sketch-to-drawio

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

Sketch to Drawio

Rebuild academic paper illustrations using bitmap sketches as references for composition, modules, and relationships, with native draw.io shapes, editable text, and standalone SVG icons. The sketch itself is never embedded as a background or full image in the final product.

Input & Output

Input is specified by the user or found in the workspace:

  • Sketch bitmap (PNG/JPG, required);
  • Optional specification file / textual description (provides formal text, data, colors, etc., and takes precedence where present).

Output goes to the user-specified directory, with filenames derived from a slug of the figure name (example slug <fig>):

  • <fig>.drawio: Editable source file (all objects editable);
  • <fig>.svg / <fig>.png: Final export (PNG on white background, suitable for papers/Word documents);
  • <fig>-icon-attribution.md: Icon sources and processing log;
  • <fig>-QC.md: Quality checklist and items requiring confirmation;
  • Intermediate icon files placed in the user-specified reference directory.

Workflow

  1. Read & Analyze: Identify modules, titles, arrow directions, container hierarchies; ignore text/numbers/formulas/watermarks from the sketch (use placeholders and mark as "needs confirmation" unless provided by a spec).
  2. Element Planning: Determine functional semantics for each graphic element and classify them first into simple functional icons (single meaning: car, file, shield, search) or complex illustrations/scenes (multi-element, decorative, e.g., mountain landscape) — then process according to the corresponding escalation ladder.
  3. Native Redraw: Rebuild all modules, containers, connections, and text using draw.io XML; layout left-to-right or top-to-bottom with clear reading order.
  4. Export & Self-Check: Export PNG preview and visually inspect (cropping, overlaps, misalignment, broken lines, arrow directions, font sizes, icon consistency, color distinguishability); fix pure layout issues by editing XML and re-exporting until passing.
  5. Deliver Ledgers: Write attribution and QC files, and summarize all needs_user_confirmation items in the final response.

Graphic Element Processing Priority (evaluated independently per element)

Simple functional icons follow A → B → C:

  • A. Open-source SVG First: Default to consistent Lucide monochrome line style; when insufficient, search Iconify open-source icon sets (medical/device sets prefer mdi, fluent). Do not mix styles within a single figure; record set, name, license, and attribution requirements. See references/icon-sourcing.md for search and download mechanics; use scripts/fetch_icon.py for downloading.
  • B. Trace sketch icons when not found: Crop, sharpen (enlarge, denoise, remove background, do not fabricate details not present in the original), convert to SVG via vtracer/Inkscape, then preferably redraw with geometric shapes matching the outline; only insert a standalone SVG (not rasterized) if redrawing is impossible. If tools are missing, fall back directly to C and record. See references/icon-tracing.md for judgment and commands.
  • C. Conservative generic shapes when still unreliable: Do not guess semantics. Data → file/cylinder; processing → rounded rectangle/gear; system → container/cloud/server; person → human outline; input/output → directional arrow/file box; completely uncertain → non-decorative rounded rectangle with clear text label; title also unreliable → placeholder text [needs confirmation]. All marked as items needing confirmation; classification criteria in references/qc.md.

Complex illustrations/scenes follow A′ → B′ → C′ → D′ → E, with two principles: style consistency over semantic matching; faithfulness to the original over recomposition (recomposition is a major source of visual clutter). Escalate down stepwise, using the fallback only as a last resort:

  • A′. Same-set combined illustrations (preferred, with quality threshold): Use multiple elements from the same icon set as the whole figure, composed with z-order occlusion (e.g., Lucide mountain-snow in the back + tree-pine×2 on sides + route in front); use 2–3 colors from the existing palette for foreground-background layering. Quality threshold: ≤3 elements, clear size hierarchy, restrained overlap; if still cluttered at target size, revise at most once then downgrade — do not polish repeatedly.
  • B′. Crop from original + color tracing ("vectorized cropping upscale"): Directly crop the illustration from the sketch → vectorize via vtracer --colormode color → palette map then visually inspect; keep fully vector, faithful to original composition.
  • C′. Crop from original + raster upscale (decoration patch allows raster): Crop, enlarge 2–4× + denoise + light sharpen (scripts/embed_raster.py), wrap PNG in SVG <image> then percent-encode embed; crop only the illustration, not text; prepare resolution at 2–3× display size.
  • D′. Palette-mapped color set / native shape combination: Choose a flat geometric color set + palette mapping (gradient-based emoji sticker style is an anti-pattern), or use basic shapes to compose a simplified scene.
  • E. Fallback: Monochrome line icon combination (e.g., Lucide route+cloud-sun); if still not possible, downgrade to C generic shapes.

See references/illustrations.md for detailed judgment, commands, and license tables.

Icons and illustrations are supplementary elements; they must not replace key text or logical relationships.

Academic Figure Constraints

  • White background, 3–5 low-saturation colors, uniform line width/radius/arrow style; default optimized for A4 page width — titles and key labels remain readable after scaling down.
  • Color illustrations limited to 1–2 per figure as visual anchors; all other elements remain monochrome line style; mixing styles within a figure applies to icons and illustrations alike — style inconsistency triggers QC.
  • For Chinese papers, check CJK font availability on the export side (missing characters become boxes; must check during self-inspection).

Anti-Hallucination Guards

  • Do not fabricate research processes, technical details, variables, methods, conclusions, or numerical values.
  • Sharpening must not fabricate details not present in the original; if unrecognizable, downgrade to C; never generate potentially incorrect new icons.
  • Any case of low-confidence semantic judgment, missing text/data, or style override — always include in the QC checklist as items needing confirmation.

Relationship with Other Skills

draw.io XML syntax, shape search, export CLI mechanics, and troubleshooting reuse drawio-skill (headless export uses xvfb-run -a drawio --no-sandbox ...; its troubleshooting covers root/no-display scenarios, etc.). This skill does not duplicate those mechanics.

Related Skills