SVG laden, Effekte anwenden, als PNG speichern

Demonstriert den Import eines SVG-Strings, dessen Rasterung in hoher Auflösung und die Anwendung von Post-Processing-Effekten wie Unschärfe und Vignette.

OUTPUT
OUTPUT — SVG laden, Effekte anwenden, als PNG speichern
JavaScript
// Load SVG, apply effects, save as PNG
// demo_svg_import.js
//!OUTPUT: OUTPUT

// demo_svg_import.js — Load an SVG, apply effects, save as PNG
//
// Demonstrates Engine.loadSVG() + standard image effects.
// The INPUT slot is unused here; the SVG is generated inline.

// ── 1. Create a simple SVG with shapes ─────────────────────────────────────
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="320" height="240">
  <defs>
    <radialGradient id="bg" cx="50%" cy="50%" r="70%">
      <stop offset="0%"   stop-color="#1a1a2e"/>
      <stop offset="100%" stop-color="#16213e"/>
    </radialGradient>
    <radialGradient id="glow" cx="50%" cy="50%" r="60%">
      <stop offset="0%"   stop-color="#e94560" stop-opacity="0.9"/>
      <stop offset="100%" stop-color="#e94560" stop-opacity="0.0"/>
    </radialGradient>
  </defs>

  <!-- Background -->
  <rect width="320" height="240" fill="url(#bg)"/>

  <!-- Glow sphere -->
  <ellipse cx="160" cy="120" rx="80" ry="80" fill="url(#glow)"/>

  <!-- Rings -->
  <ellipse cx="160" cy="120" rx="110" ry="40" fill="none" stroke="#e94560" stroke-width="2" stroke-opacity="0.7"/>
  <ellipse cx="160" cy="120" rx="140" ry="55" fill="none" stroke="#0f3460"  stroke-width="1.5" stroke-opacity="0.5"/>

  <!-- Text -->
  <text x="160" y="218" font-family="sans-serif" font-size="14" fill="#e94560"
        text-anchor="middle" opacity="0.85">mlc · kornia · pipeline</text>
</svg>`;

// ── 2. Rasterize SVG at 2× resolution ──────────────────────────────────────
const img = Engine.loadSVG(svg, 2.0);   // → 640×480 image

// ── 3. Apply effects ────────────────────────────────────────────────────────
img.gaussianBlur(0.8);   // subtle softening
img.brightness(1.08);    // slightly brighter
img.vignette(0.55);      // darken corners for depth

// ── 4. Save ─────────────────────────────────────────────────────────────────
Engine.saveImage(img, "OUTPUT");

`SVG imported and processed: ${img.width}×${img.height}`;

// © 2026 Michael Lechner · mlc OpticScript · https://mlcgo.eu · Elastic License 2.0