Skip to content

Convert an SVG to a PNG using a headless browser

License

Notifications You must be signed in to change notification settings

pumpncode/svg-to-png

svg-to-png

Convert SVG files to PNG using a headless browser for pixel-perfect rendering.

Why

Most SVG-to-PNG tools use librsvg or similar, which often renders SVGs differently than browsers do. This tool uses a real Chromium browser (via Astral) to ensure the output matches what you see in your browser.

Installation

deno add jsr:@pumpn/svg-to-png

Usage

CLI

deno task svg-to-png -i input.svg -o output.png

With resizing:

deno task svg-to-png -i input.svg -o output.png --width 512
deno task svg-to-png -i input.svg -o output.png --height 256
deno task svg-to-png -i input.svg -o output.png --width 512 --height 512

Programmatic

import svgToPng from "@pumpn/svg-to-png";

await svgToPng("input.svg", "output.png");

// With options
await svgToPng("input.svg", "output.png", {
  resizeWidth: 512,
  resizeHeight: 512,
  compress: true // uses oxipng (default: true)
});

Requirements

  • Deno 2.0+
  • oxipng (optional, for PNG compression)

License

BSD Zero Clause License

About

Convert an SVG to a PNG using a headless browser

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published