svg-to-png-buffer
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

SVG to PNG Buffer

This package provides a simple utility function to convert SVG files to PNG format using Node.js. It utilizes the canvas library to handle the image conversion.

Installation

Before installing, make sure you have Node.js installed on your machine. Then, you can install the package using npm:

npm install svg-to-png-buffer

Usage

Here's how you can use the svgFileToPngBuffer function to convert an SVG file to a PNG buffer:

import { svgFileToPngBuffer } from 'svg-to-png-buffer';

async function convertSvgToPng() {
  try {
    const pngBuffer = await svgFileToPngBuffer('path/to/your/file.svg');
    console.log('PNG buffer created:', pngBuffer);
  } catch (error) {
    console.error('Failed to convert SVG to PNG:', error);
  }
}

convertSvgToPng();

Functionality

  • svgFileToPngBuffer(filePath): This async function takes a file path to an SVG file as input and returns a Promise that resolves to a PNG buffer. It reads the SVG file, converts it to a base64 data URI, loads this into a canvas, and then converts the canvas to a PNG data URL.

Requirements

  • Node.js

License

This project is licensed under the MIT License - see the LICENSE file for details.

Readme

Keywords

Package Sidebar

Install

npm i svg-to-png-buffer

Weekly Downloads

80

Version

1.0.1

License

ISC

Unpacked Size

3.55 kB

Total Files

4

Last publish

Collaborators

  • shirtlessdev