canvg
Version:
JavaScript SVG parser and renderer on Canvas.
79 lines (54 loc) • 2.22 kB
Markdown
"right" width="120" height="120" alt="Logo" src="website/static/img/logo.svg">
[![NPM version][npm]][npm-url]
[![Dependencies status][deps]][deps-url]
[![Build status][build]][build-url]
[![Coverage status][coverage]][coverage-url]
[ ]: https://img.shields.io/npm/v/canvg.svg
[ ]: https://npmjs.com/package/canvg
[ ]: https://img.shields.io/librariesio/release/npm/canvg
[ ]: https://libraries.io/npm/canvg/tree
[ ]: https://img.shields.io/github/actions/workflow/status/canvg/canvg/ci.yml?branch=master
[ ]: https://github.com/canvg/canvg/actions
[ ]: https://img.shields.io/codecov/c/github/canvg/canvg.svg
[ ]: https://app.codecov.io/gh/canvg/canvg
JavaScript SVG parser and renderer on Canvas. It takes the URL to the SVG file or the text of the SVG file, parses it in JavaScript and renders the result on Canvas. It also can be used to rasterize SVG images.
<a href="#quickstart">Quickstart</a>
<span> • </span>
<a href="#docs">Docs</a>
<span> • </span>
<a href="https://canvg.js.org/demo/">Demo</a>
<br />
<hr />
Install this library using your favorite package manager:
```sh
pnpm add canvg
yarn add canvg
npm i canvg
```
Then, just import `Canvg` and use it:
```js
import { Canvg } from 'canvg';
let v = null;
window.onload = async () => {
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
v = await Canvg.from(ctx, './svgs/1.svg');
// Start SVG rendering with animations and mouse handling.
v.start();
};
window.onbeforeunload = () => {
v.stop();
};
```
[ ](https://canvg.js.org/api)
<br />
- [Migration to v4](https://canvg.js.org/docs/migration-to-v4)
- [API](https://canvg.js.org/api/classes/Canvg)
- [Examples](https://canvg.js.org/examples)
The end goal is everything from the [SVG spec](http://www.w3.org/TR/SVG/). The majority of the rendering and animation is working. If you would like to see a feature implemented, don't hesitate to add it to the issues list, or better is to create pull request 😎
<img align=