Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@resvg/resvg-wasm
Advanced tools
A high-performance SVG renderer and toolkit, powered by Rust based resvg and napi-rs
@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.
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);
})();
Sharp is a high-performance image processing library for Node.js. It supports various image formats, including SVG, and can convert SVG files to raster images like PNG and JPEG. Compared to @resvg/resvg-wasm, Sharp offers a broader range of image processing capabilities but may not be as specialized in SVG rendering.
svg2png is a simple utility for converting SVG files to PNG images. It uses Puppeteer to render the SVG in a headless Chromium browser. While it provides a straightforward way to convert SVG to PNG, it may not be as performant or versatile as @resvg/resvg-wasm.
Canvg is a library that allows you to render SVG files on an HTML5 canvas. It can be used in both Node.js and browser environments. While it provides good support for rendering SVGs, it may not offer the same level of performance and output format flexibility as @resvg/resvg-wasm.
FAQs
A high-performance SVG renderer and toolkit, powered by Rust based resvg and napi-rs
The npm package @resvg/resvg-wasm receives a total of 103,029 weekly downloads. As such, @resvg/resvg-wasm popularity was classified as popular.
We found that @resvg/resvg-wasm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.