Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@resvg/resvg-wasm

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@resvg/resvg-wasm

A high-performance SVG renderer and toolkit, powered by Rust based resvg and napi-rs

  • 2.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
153K
decreased by-1.55%
Maintainers
2
Weekly downloads
 
Created

What is @resvg/resvg-wasm?

@resvg/resvg-wasm is an npm package that provides WebAssembly (Wasm) bindings for the Resvg library, which is used for rendering SVG files. This package allows you to convert SVG files to raster images (like PNG) or other vector formats, manipulate SVG elements, and perform various SVG-related operations directly in JavaScript environments, including Node.js and web browsers.

What are @resvg/resvg-wasm's main functionalities?

Convert SVG to PNG

This feature allows you to convert an SVG file to a PNG image. The code reads an SVG file, uses the Resvg library to render it, and then saves the output as a PNG file.

const { Resvg } = require('@resvg/resvg-wasm');
const fs = require('fs');

(async () => {
  const svgData = fs.readFileSync('example.svg', 'utf8');
  const resvg = new Resvg(svgData);
  const pngData = resvg.render().asPng();
  fs.writeFileSync('output.png', pngData);
})();

Convert SVG to JPEG

This feature allows you to convert an SVG file to a JPEG image. The code reads an SVG file, uses the Resvg library to render it, and then saves the output as a JPEG file.

const { Resvg } = require('@resvg/resvg-wasm');
const fs = require('fs');

(async () => {
  const svgData = fs.readFileSync('example.svg', 'utf8');
  const resvg = new Resvg(svgData);
  const jpegData = resvg.render().asJpeg();
  fs.writeFileSync('output.jpg', jpegData);
})();

Manipulate SVG Elements

This feature allows you to manipulate SVG elements, such as changing attributes like width and height. The code reads an SVG file, modifies its attributes, and then saves the modified SVG.

const { Resvg } = require('@resvg/resvg-wasm');
const fs = require('fs');

(async () => {
  const svgData = fs.readFileSync('example.svg', 'utf8');
  const resvg = new Resvg(svgData);
  resvg.setAttribute('width', '500');
  resvg.setAttribute('height', '500');
  const modifiedSvg = resvg.toSvgString();
  fs.writeFileSync('modified.svg', modifiedSvg);
})();

Other packages similar to @resvg/resvg-wasm

Keywords

FAQs

Package last updated on 09 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc