1. canvg
JavaScript SVG parser and renderer on Canvas.
canvg
Package: canvg
Created by: canvg
Last modified: Mon, 22 Apr 2024 17:10:09 GMT
Version: 4.0.2
License: MIT
Downloads: 4,944,204
Repository: https://github.com/canvg/canvg

Install

npm install canvg
yarn add canvg

canvg

Logo

NPM version
Dependencies status
Build status
Coverage status

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.

Quickstart
  •  
Docs
  •  
Demo


Quickstart

Install this library using your favorite package manager:

 pnpm add canvg
# or
yarn add canvg
# or
npm i canvg

Then, just import Canvg and use it:

 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();
};

Description of all exports you can find in Documentation.


Docs

What's implemented?

The end goal is everything from the SVG spec. 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 😎

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code