canvg parses SVG from a URL or raw text in JavaScript and draws the result on an HTML canvas. It can also turn SVG graphics into raster images.
Overview
canvg is a JavaScript library that reads SVG input, parses it in the browser runtime, and renders the graphic on a Canvas 2D context. You supply either the URL of an SVG file or the SVG markup as text.
After initialization, the library can start rendering with support for animation and pointer handling shown in the quickstart example. The stated goal is broad coverage of the SVG specification; the documentation notes that most rendering and animation behavior is already in place.
You install it through common JavaScript package managers and import the Canvg API in application code. Documentation covers exports, migration notes, examples, and a live demo page.
Typical uses include displaying SVG assets where native SVG support is limited and producing bitmap output from vector sources.
Key features
- Parses SVG from URL or text
- Renders to HTML canvas
- SVG rasterization support
- Animation rendering
- Mouse interaction handling
- Package manager installation
- Documented public API
Use cases
- Canvas-based SVG display
- Converting SVG to raster images
- Web apps with vector graphics
- Interactive SVG on canvas