Skip to content

Repository files navigation

AI SVG Generator for Inkscape

Inkscape Python License

Generate, review, and refine SVG graphics with AI β€” directly inside Inkscape

An Inkscape extension that turns text descriptions into vector graphics using OpenAI, Anthropic Claude, Google Gemini, Azure OpenAI, local Ollama models, or any custom OpenAI-compatible server β€” with a review-first gallery so nothing lands on your canvas until you approve it.

πŸ“Ί Demo

Watch the Demo

Click to watch the tutorial on YouTube


✨ Features

  • πŸ€– Seven AI providers

    Provider Auth Notes
    OpenAI API key GPT-5.x, GPT-4.1, o3/o4 reasoning models
    Anthropic Claude API key Claude Opus 4.8, Sonnet 5, Haiku 4.5
    Google Gemini API key Gemini 2.5 Pro / Flash
    Azure OpenAI API key + endpoint Your own deployments
    Ollama none (local) Any locally installed model
    Custom (OpenAI-compatible) optional key + endpoint LM Studio, vLLM, Groq, Together, DeepSeek…
  • πŸ–ΌοΈ Review-first workflow β€” after generation, a gallery shows every variation rendered. Check what you want, Refine with a follow-up instruction ("make the roof red"), Regenerate, Preview/Copy/Save β€” and only then Insert Selected. Discard All leaves your document untouched.

  • ⚑ Fast & responsive β€” variations generate in parallel; streaming providers show live character counts; Cancel returns immediately.

  • πŸ›‘οΈ Safe by default β€” generated SVG is sanitized (scripts, event handlers, foreignObject, javascript: URIs stripped) before it is previewed or inserted.

  • 🎨 Rich style controls β€” style presets, color schemes, complexity, stroke styles, negative prompts, custom system prompt β€” all editable as markdown files under prompts/.

  • πŸ“ Flexible output β€” preset/custom sizes, aspect ratios, target layer, grouping, positioning, multiple variations, save-to-disk, link-or-embed.

  • 🧰 Workflow tools β€” prompt history with search & replay, named templates, live model-list refresh per provider, API key test button, selection-as-context and selection-refine modes.


πŸ“¦ Requirements

Component Version Purpose
Inkscape 1.0+ Runs the extension (GTK3 + its bundled Python)
Python 3.8+ Ships with Inkscape β€” nothing to install
Internet β€” API access (not needed for Ollama)

No pip packages required β€” the extension uses only the Python standard library. librsvg (bundled with Inkscape) enables thumbnail previews.


πŸš€ Installation

  1. Find your extensions directory (Edit β†’ Preferences β†’ System β†’ User extensions):

    OS Path
    Windows %APPDATA%\inkscape\extensions\
    macOS ~/Library/Application Support/org.inkscape.Inkscape/config/inkscape/extensions/
    Linux ~/.config/inkscape/extensions/
  2. Copy (or clone) this whole folder there as svg_maker/:

    git clone https://github.com/YouvenZ/svg_maker_ink.git [extensions-dir]/svg_maker
  3. Restart Inkscape. The extension appears under Extensions β†’ Generate β†’ AI SVG Generator.


🎯 Quick Start

  1. Extensions β†’ Generate β†’ AI SVG Generator
  2. Pick a provider and paste an API key (or use local Ollama β€” no key)
  3. Type a prompt: A simple house icon with a chimney
  4. Click Generate
  5. In the review gallery: refine if needed, check the variations you like, click Insert Selected

πŸ“– The Dialog

Tab Purpose
Prompt Provider + key, preset, prompt text, negative prompt, selection context/refine
Model Model picker with live ⟳ Refresh, temperature, max tokens, timeout, retries, seed
Size Presets (200–800 px), aspect ratios, custom dimensions
Style Visual style, complexity, color scheme, stroke style, gradients
Output Position, grouping, variations (1–4), animations, accessibility, target layer, page auto-fit
Save Save-to-disk directory, filename prefix, embed vs. link
Advanced Custom system prompt, named prompt templates
History Searchable prompt history β€” double-click to replay
Help In-dialog quick reference

The Review Gallery

After generation you get a gallery β€” nothing has touched your document yet:

  • Each variation card: rendered thumbnail, byte size, Insert checkbox, Preview / Copy / Save buttons
  • Refine β€” pick a variation, type a follow-up instruction; the current SVG is sent back to the model and replaced in place. Iterate as often as you like.
  • Regenerate β€” re-run the original prompt for one variation
  • Insert Selected β€” inserts only the checked variations
  • Discard All β€” closes with zero changes to your document

To restore the old auto-insert behaviour (e.g. for scripted use), set "review_before_insert": false in config.json.


βš™οΈ Configuration

API keys (priority order)

  1. Direct input in the Provider tab (check Save entered key to persist)
  2. Environment variable β€” OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY, AZURE_OPENAI_API_KEY, CUSTOM_OPENAI_API_KEY
  3. config.json in the extension folder (flat keys):
{
  "openai_api_key": "sk-…",
  "anthropic_api_key": "sk-ant-…",
  "google_api_key": "…",
  "default_provider": "anthropic",
  "default_model": "claude-opus-4-8",
  "default_save_directory": "C:/Users/you/Pictures/AI_Images",
  "review_before_insert": true
}

⚠️ config.json stores keys as plain text. Prefer environment variables on shared machines. config.json is gitignored.

Files created by the extension

File Purpose
config.json Saved keys and defaults
svg_llm_history.json Prompt history (last 50)
svg_llm_templates.json Named prompt templates

All are gitignored and stay on your machine.


πŸ”Œ Provider Setup

OpenAI

Key from platform.openai.com/api-keys. Reasoning models (o3, o4-mini, gpt-5*) are handled automatically (correct token parameter, no temperature).

Anthropic Claude

Key from console.anthropic.com. Recommended: claude-opus-4-8 (best quality) or claude-haiku-4-5 (fast/cheap). Newest models ignore the temperature setting (API restriction).

Google Gemini

Key from aistudio.google.com/apikey. Recommended: gemini-2.5-flash.

Azure OpenAI

Enter your resource endpoint (https://your-resource.openai.azure.com) and key; the model field is your deployment name.

Ollama (local, free)

ollama pull llama3.1   # once
ollama serve

Select provider Ollama β€” installed models are auto-discovered. No key.

Custom (OpenAI-compatible)

Point the Endpoint field at any /v1-style base URL: http://localhost:1234/v1 (LM Studio), https://api.groq.com/openai/v1, etc. Type the model name in the Custom model name field.


πŸ”§ Customization

Prompts are markdown files

Everything sent to the model lives under prompts/ β€” edit without touching code:

prompts/
β”œβ”€β”€ system_prompt.md      # the system prompt
β”œβ”€β”€ presets/              # icon, logo, diagram, flowchart, …
β”œβ”€β”€ styles/               # minimal, flat, isometric, cartoon, …
β”œβ”€β”€ colors/               # warm, pastel, neon, …
β”œβ”€β”€ complexity/           # simple, medium, complex
└── strokes/              # thin, thick, none, variable

Add a new file (e.g. styles/blueprint.md) and reference it, or edit existing ones. Missing files fall back to built-in defaults.

Templates

Save any prompt + settings combination as a named template in the Advanced tab, and reload it with one click.


πŸ§ͺ Testing

Everything except the Inkscape insertion can be tested outside Inkscape:

# Offline unit checks (sanitizer, cleaner, dimension fixer, registry)
python test_svg_generation.py --self-test

# Live end-to-end call using your config.json / env keys
python test_svg_generation.py --provider anthropic --stream
python test_svg_generation.py --provider ollama --model llama3.1

πŸ› Troubleshooting

Extension not in the menu
  • Confirm the folder layout: [extensions]/svg_maker/svg_llm.inx + svg_llm.py
  • Restart Inkscape fully
  • Check Edit β†’ Preferences β†’ System β†’ Open Error Log
API error (401 / 403)
  • Use the Test button next to the key field
  • Check for stray spaces, expiry, or org restrictions on the key
Model error (400)
  • Click ⟳ Refresh in the Model tab to load the provider's current list β€” hardcoded model names go stale
  • For Azure, the model must be your deployment name
No thumbnails in the review gallery
  • Thumbnails need librsvg (bundled with Inkscape on all platforms); when missing, a source-code preview is shown instead β€” everything else works
Ollama not reachable
  • Start it: ollama serve, then verify curl http://localhost:11434/api/tags
  • Check the endpoint field if you run it on another port/host

πŸ“ File Structure

svg_maker/
β”œβ”€β”€ svg_llm.inx              # Inkscape extension registration
β”œβ”€β”€ svg_llm.py               # Main extension (effect flow, document insertion)
β”œβ”€β”€ svg_llm_common.py        # Provider registry, sanitizer, HTTP/SSE helpers
β”œβ”€β”€ svg_llm_dialog.py        # GTK3 main dialog + progress dialog
β”œβ”€β”€ svg_llm_review.py        # Review-first result gallery
β”œβ”€β”€ svg_llm_prompts.py       # Markdown prompt loader
β”œβ”€β”€ svg_llm_openai.py        # ── provider modules ──
β”œβ”€β”€ svg_llm_anthropic.py
β”œβ”€β”€ svg_llm_google.py
β”œβ”€β”€ svg_llm_azure.py
β”œβ”€β”€ svg_llm_ollama.py
β”œβ”€β”€ svg_llm_custom.py
β”œβ”€β”€ prompts/                 # Editable prompt fragments (markdown)
β”œβ”€β”€ test_svg_generation.py   # Self-tests + live smoke test
└── example_config.json      # Config template

πŸ’‘ Prompt Tips

  1. Be specific: "A red apple with a leaf" beats "an apple"
  2. Use presets β€” they add tuned instructions for icons, logos, diagrams…
  3. Refine instead of retrying β€” the review gallery's Refine keeps what works and changes only what you ask
  4. Use the negative prompt for things to avoid ("text, shadows, 3D")
  5. Select elements first and enable selection context to match a style

🀝 Contributing

  1. Fork, branch (git checkout -b feature/x), commit, PR
  2. Run python test_svg_generation.py --self-test before submitting
  3. Provider modules are self-contained β€” adding a provider means one new svg_llm_<name>.py (with generate() / fetch_models()) plus a registry entry in svg_llm_common.py

πŸ“„ License

MIT β€” see the license file.

πŸ“§ Support

πŸ”„ Changelog

v2.0.0 (2026-07)

  • ✨ Review-first workflow: gallery with thumbnails, per-variation insert, iterative Refine, Regenerate β€” nothing auto-inserts
  • ✨ Parallel variation generation + streaming progress + instant Cancel
  • ✨ SVG sanitization (scripts/handlers/foreignObject stripped)
  • ✨ Current model support: Claude Opus 4.8/Sonnet 5, GPT-5.x/o-series (correct parameters per model), Gemini 2.5
  • πŸ”§ Single shared provider registry; root-tag-only dimension fixing; UTF-8 file output; offline self-test suite

v1.0.0 (2024)

  • Initial release: OpenAI/Anthropic/Google/Ollama, styles, sizing, variations, history, GTK dialog

About

Create SVG with text directly within inkscape with generative AI

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages