ScreenshotNeo

BlogHow-to

How to Convert SVG to High-Resolution PNG

Convert SVG files to sharp PNGs with Inkscape, rsvg-convert, ImageMagick, Python, and Node.js. Choose dimensions, DPI, transparency, and batch workflows.

By the ScreenshotNeo team1 October 20266 min read

Direct answer: SVG is vector artwork, so it has no single intrinsic PNG resolution. Choose the target PNG pixel dimensions for its intended use, then render the SVG with a tool such as Inkscape or rsvg-convert. Preserve the aspect ratio, inspect the exported dimensions and transparency, and use DPI only when physical document units or print size matter.

1. Choose the PNG size before converting

For web and screen use, choose pixels directly. A 2,000-pixel-wide PNG is suitable when the image must display sharply at widths up to about 1,000 CSS pixels on a two-device-pixel-ratio screen. Exporting a larger raster gives you room to resize down; enlarging a small PNG later cannot restore vector detail.

Use case How to choose output
Web image Set the required pixel width or height. Keep the SVG aspect ratio.
Retina asset Export at roughly twice the intended CSS dimensions, then display it smaller.
Print Calculate pixels from physical size and print density: pixels = inches × DPI.
Icon or logo Export the exact sizes required by the consuming system, often several PNG sizes.

DPI is a rasterization scale for documents that use physical units. It does not create extra artwork detail. The rsvg-convert manual documents 96 DPI as the default for physical units and supports explicit values such as 300 DPI.

2. Convert SVG to PNG with Inkscape

Inkscape provides a GUI and a repeatable command-line exporter. The official command-line documentation shows this basic conversion:

inkscape --export-type="png" my_file.svg

This creates my_file.png. To control exact width, height, or DPI, use the export options supported by your installed Inkscape version. The command-line reference explains that export width, height, and DPI can override the document’s stored export hint. Check Inkscape’s current command-line manual because flags vary by version.

# Example: export a named file at a chosen width (verify flags with your version)
inkscape input.svg --export-filename=output.png --export-width=2048

When only one dimension is supplied, the renderer can preserve the document’s proportions. If both width and height are supplied, confirm that the result is not unintentionally stretched.

3. Convert with rsvg-convert

rsvg-convert is convenient for scripts and pipelines. Supply one or both dimensions and use --keep-aspect-ratio when proportions must remain unchanged:

rsvg-convert --width=1024 --height=768 --keep-aspect-ratio input.svg > output.png

For physical-unit documents, set rasterization density explicitly:

rsvg-convert --dpi-x=300 --dpi-y=300 input.svg > output.png

Read the installed manual or the rsvg-convert reference for supported SVG features and options.

4. Use ImageMagick carefully

ImageMagick can delegate SVG rendering to Inkscape, RSVG, or its internal renderer. The selected delegate affects supported features and sizing behavior. Its documentation warns that -size is ignored when the Inkscape renderer is used.

magick -background none input.svg output.png

-background none requests an alpha channel instead of a solid background. Confirm which delegate is installed and inspect the output dimensions. See ImageMagick’s SVG format notes.

5. A repeatable Python workflow

This script calls rsvg-convert, preserves proportions, and fails clearly when the executable is missing:

from pathlib import Path
import shutil
import subprocess

source = Path("input.svg")
target = Path("output.png")
converter = shutil.which("rsvg-convert")
if converter is None:
    raise SystemExit("Install librsvg so rsvg-convert is available on PATH")

subprocess.run([
    converter,
    "--width=2048",
    "--keep-aspect-ratio",
    str(source),
], stdout=target.open("wb"), check=True)
print(f"Wrote {target}")

For a print workflow, replace the width option with --dpi-x and --dpi-y, or calculate the exact pixel dimensions first.

6. A repeatable Node.js workflow

Node.js can run the same renderer and stream its PNG output to disk:

import { spawn } from "node:child_process";
import { createWriteStream } from "node:fs";

const output = createWriteStream("output.png");
const child = spawn("rsvg-convert", [
  "--width=2048",
  "--keep-aspect-ratio",
  "input.svg",
]);

child.stdout.pipe(output);
child.stderr.on("data", data => process.stderr.write(data));
child.on("error", err => {
  console.error("Could not start rsvg-convert:", err.message);
  process.exitCode = 1;
});
child.on("close", code => {
  if (code !== 0) process.exitCode = code;
});

7. Batch conversion

For a directory of SVG files, keep the renderer and options identical so every output follows the same sizing policy.

mkdir -p png
for file in svg/*.svg; do
  name=$(basename "$file" .svg)
  rsvg-convert --width=2048 --keep-aspect-ratio "$file" > "png/$name.png"
done

Use separate commands when different artwork needs different dimensions. If an SVG contains named objects that must be exported independently, use Inkscape’s object export options from the version-specific manual.

8. Verify dimensions, alpha, and edges

Always inspect the generated file. ImageMagick’s identify reports dimensions and channels:

identify -format '%m %wx%h %[channels]\n' output.png

Check that:

  • The pixel width and height match the requirement.
  • The aspect ratio matches the SVG.
  • Transparent artwork still has an alpha channel.
  • Text uses available fonts and has no substituted glyphs.
  • Filters, masks, gradients, clipping paths, and embedded images render correctly.

9. Transparency, fonts, and complex SVG features

Transparency

SVG backgrounds may be transparent even when a preview application displays white. Use a renderer option such as ImageMagick’s -background none, then verify the PNG’s alpha channel. If the final destination does not support transparency, render against the intended background color instead.

Fonts

Conversion depends on fonts installed in the rendering environment. Install the required fonts or convert critical text to paths in the source artwork. This increases portability but makes text harder to edit.

Filters and embedded assets

Blur, shadows, masks, external stylesheets, and embedded raster images can differ between renderers. Test representative files with the renderer used in production. Keep external assets accessible or embed them when the format and workflow permit.

10. Troubleshooting

Symptom Likely cause Fix
PNG is the wrong size Document export hints or physical units determined the raster size. Set explicit width, height, or DPI and check the installed tool’s flags.
Artwork is stretched Both dimensions were forced without preserving the aspect ratio. Set one dimension or use --keep-aspect-ratio.
Background is opaque The renderer used a default background. Use a transparent background option such as -background none and verify alpha.
Text looks different Required fonts are missing or substituted. Install fonts, package them with the build environment, or convert text to paths.
Filters or masks disappear Renderer support differs from the SVG authoring application. Try Inkscape or librsvg, simplify unsupported effects, and compare output.
rsvg-convert: command not found librsvg is not installed or is not on PATH. Install the librsvg command-line package for your operating system.
ImageMagick ignores -size ImageMagick selected the Inkscape delegate. Set dimensions through the selected delegate’s options and inspect the result.
External images are missing Relative paths or network resources are unavailable. Use absolute, accessible paths or embed the assets before conversion.

11. Performance and reliability

  • Reuse a long-lived conversion process or worker for large batches when your deployment supports it; process startup can dominate small files.
  • Keep source SVGs and fonts local for predictable builds. Network-linked assets introduce failures and variable output.
  • Export only the largest size you need. Very large PNGs consume more CPU, memory, storage, and transfer bandwidth.
  • Use deterministic renderer versions in CI and compare a sample output after upgrades.
  • For transparent assets, test against both light and dark backgrounds to reveal matte colors or edge halos.

12. Or skip the browser setup

If the SVG is hosted on a public URL or you need a rendered website image rather than a local file, ScreenshotNeo provides a single screenshot request. Its capture options include PNG, JPEG, WebP, PDF, custom viewport and retina scale, full-page capture, CSS selectors, custom CSS and JavaScript, and transparent backgrounds. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Cookie banners, newsletter popups, and chat widgets are removed before the shot. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. An MCP server lets Claude, Cursor, and other MCP clients take screenshots. The free plan includes 1,000 screenshots each month with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

13. FAQ

Is a 300 DPI PNG always higher quality?

No. DPI affects rasterization of physical units and print sizing. The artwork detail is determined by the SVG and the resulting pixel dimensions.

Should I export width or height?

Set the dimension controlled by your layout and preserve the aspect ratio. Set both only when the target canvas has a deliberate fixed ratio.

Can I convert SVG to PNG without installing a GUI?

Yes. Inkscape and rsvg-convert both support command-line workflows, and either can run in CI or a server worker.

Why does my PNG look blurry?

It may have been rasterized at too few pixels, enlarged afterward, or rendered with missing fonts or unsupported effects. Export at the required size and inspect the source features.