Skip to main content

AiSvg

AI SVG visual asset generation β€” prompt builder + SVG security sanitizer.

Status​

KeyValue
Layercomposite
TierL1
Statuswip
Version0.9.0
PriceFree (free)
CategoryContent

Overview​

Overview​

AiSvg is a Composite Plugin for generating and validating AI-created SVG visual assets. It provides a standard prompt builder and SVG sanitizer for content documents, landing pages, help pages, reports, and other web content.

LLM calls are delegated to project AI adapters such as AiRelay. AiSvg owns the Pure boundary for prompt composition + result validation.

Core Components​

Enums​

EnumCases
SvgVisualKindCARTOON / PHOTO / DIAGRAM / ICON
StylePresetFLAT / CARTOON / LINE / HAND_DRAWN

Each has visualHint() / styleHint() for prompt construction.

PromptBuilder (Pure)​

Extracted from academy.how's IllustrationGenerator::buildPrompt and generalized. Inputs: caption + kind + style + locale. Auto-includes viewBox, locale title language, audience, security constraints, and size limits.

SvgSanitizer (Pure)​

Validates LLM-generated SVG safety + format.

  • Auto-strips Markdown code fence
  • Validates <svg> start + </svg> end
  • Blocks dangerous tags (script / foreignObject / iframe / object / embed)
  • Blocks event handlers (onclick / onload / etc)
  • Blocks unsafe URL schemes in href/xlink:href/style url(): http, https, data, javascript
  • Size limits (8KB / 60 lines)

Result: { ok, svg, issues, size_bytes, line_count }. Issue codes are i18n-able.

Configuration​

return [
'enabled' => env('PLG_AI_SVG_ENABLED', true),
'audience' => 'general web content readers',
'svg' => ['max_size_bytes' => 8192, 'max_lines' => 60, 'view_box' => '0 0 480 320'],
'forbidden' => [
'tags' => ['script', 'foreignObject', 'iframe', 'object', 'embed'],
'event_handlers' => ['onclick', 'onload', 'onmouseover', 'onerror'],
'block_external_images' => true,
'forbidden_url_schemes' => ['http:', 'https:', 'data:', 'javascript:'],
],
];

Usage​

$prompt = PromptBuilder::fromConfig(config('ai-svg'))->build(
caption: 'an apple in sunlight',
kind: SvgVisualKind::CARTOON,
style: StylePreset::FLAT,
locale: app()->getLocale(),
);

$result = $aiClient->complete($prompt);
$sanitized = SvgSanitizer::fromConfig(config('ai-svg'))->sanitize($result['text']);

if ($sanitized['ok']) {
$visualAsset->svg_content = $sanitized['svg'];
}

Origin​

Extracted from academy.how's IllustrationGenerator (320 LOC). LLM call / Eloquent save / AiRun tracking are project or AiRelay/AiTracking responsibilities.

Dependencies​

  • DocumentProcessor β€” embed SVG in Document
  • AiRelay (optional) β€” LLM call adapter
  • AiTracking (optional) β€” generation history

Roadmap​

  • Standard AiSvgAsset Model + Migration
  • Filament Resource for preview, approval, regeneration, and rollback
  • Refine prompt (user instructions + attachment images)
  • Caption β†’ SVG caching

License​

MIT

Dependencies​

Demos​


πŸ›’ View on Plugin Store: store.codebase.how/plugins/ai-svg