Skip to main content

Illustration

AI illustration (SVG) β€” prompt builder + SVG security sanitization (Layer 3 Domain).

Status​

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

Overview​

Overview​

Illustration is a Layer 3 Domain Plugin of multi-saas-kit. Provides a standard prompt builder + safety sanitizer for generating SVG illustrations via LLM, embeddable in learning content.

LLM call is delegated to AiRelay plugin; this plugin handles only the prompt composition + result validation Pure parts.

Core Components​

Enums​

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

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

PromptBuilder (Pure)​

Extracted from academy.how's IllustrationGenerator::buildPrompt. Inputs: caption + kind + style + locale. Auto-includes viewBox, locale→title-lang mapping, security constraints, size limits.

SvgSanitizer (Pure)​

Validates LLM-generated SVG safety + format.

  • Auto-strips Markdown code fence (```svg, ```xml, ```)
  • Validates <svg> start + </svg> end
  • Blocks dangerous tags (script / foreignObject / iframe / object / embed)
  • Blocks event handlers (onclick / onload / etc)
  • Blocks external images (<image href="https://...">)
  • Size limits (8KB / 60 lines)

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

Configuration​

return [
'enabled' => env('PLG_ILLUSTRATION_ENABLED', true),
'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,
],
'locale_to_title_lang' => [/* en/ja/zh/zh-TW/ko */],
];

Usage​

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

$result = LlmRelayClient::fromConfig(config('ai-relay'))->complete([
'model' => 'gpt-4o-mini',
'messages' => [['role' => 'user', 'content' => $prompt]],
]);

$sanitized = SvgSanitizer::fromConfig(config('illustration'))->sanitize($result['data']['text']);

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

Origin​

Extracted from academy.how's IllustrationGenerator (320 LOC). LLM call / Eloquent save / AiRun tracking remain in project.

Dependencies​

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

Roadmap (Phase 3+)​

  • Standard Illustration Model + Migration
  • Filament Resource
  • Refine prompt (user instructions + attachment images)
  • Multi-provider support
  • Caption β†’ SVG caching

License​

MIT

Dependencies​

Demos​


πŸ›’ View on Plugin Store: store.codebase.how/plugins/illustration