Skip to main content

Process SVG Images

About SVG processing

What is it? SVG processing rasterizes vector SVG input into a bitmap image, then applies the same Image Optimizer operations (resize, crop, watermark, quality, and optional WebP conversion).

How SVG is handled

  • SVG input is detected from extension/content and rendered to pixels.
  • Without format conversion, SVG output is served as PNG.
  • With WebP conversion enabled and browser support, output can be served as WebP.

Enable SVG processing

SVG processing is included in Image Optimizer. Configure via environment variables and query parameters.

Via environment variables

FORMATS_TO_TRANSFORM=jpg,jpeg,png,gif,svg
CONVERT_TO_WEBP=true   # Optional

Via query parameters

graphic.svg
graphic.svg?width=1200
graphic.svg?crop=1:1
graphic.svg?fmt=webp

SVG output behavior

InputParametersOutput
SVGnonePNG
SVGresize/crop/qualityPNG
SVGfmt=webp + Accept: image/webpWebP
SVGfmt=webp without WebP supportOriginal path (no forced WebP conversion)

Usage examples

<!-- SVG rasterized to PNG -->
<img src="icon.svg" alt="Icon" />

<!-- SVG resize -->
<img src="illustration.svg?width=800" alt="Illustration" />

<!-- SVG crop -->
<img src="illustration.svg?crop=16:9" alt="Illustration" />

<!-- SVG to WebP when supported -->
<img src="illustration.svg?fmt=webp" alt="Illustration" />

<!-- Full processing chain -->
<img src="illustration.svg?width=1200&crop=16:9&quality=80&fmt=webp" alt="Illustration" />

Check HTTP headers

curl -I -H "Accept: image/webp,*/*" \
  https://your-cdn.com/illustration.svg?fmt=webp

Expected headers:

  • Content-Type: image/webp (when WebP is selected)
  • X-Img-Operations includes performed operations
  • Vary: Accept (when format conversion is used)

Limitations

Zero-size SVG

  • SVG files that resolve to zero width/height are not processed.

See limitations.md for platform-level details.

Troubleshooting

SVG not processed: Verify svg is in FORMATS_TO_TRANSFORM. Unexpected PNG output: Add ?fmt=webp and confirm Accept includes image/webp. Render error/fallback: Validate SVG content and dimensions.

FORMATS_TO_TRANSFORM=jpg,jpeg,png,gif,svg
CONVERT_TO_WEBP=true