Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To convert an SVG to PNG in a web page, load the SVG as an image, draw it onto a canvas at the pixel dimensions you want, then export the canvas with toBlob(). The canvas size controls the PNG’s dimensions; the SVG’s proportions determine how to avoid stretching it. The main obstacle is usually not the conversion itself but an SVG that has not finished loading, lacks intrinsic dimensions, or depends on cross-origin resources.

Convert an SVG to a downloadable PNG in the browser

This example takes an SVG URL and desired output dimensions, waits for the image to decode, paints it to a canvas, and returns a PNG Blob. It uses browser APIs and does not require a library.

async function svgToPngBlob(svgUrl, width, height) {
  if (!Number.isInteger(width) || width <= 0 ||
      !Number.isInteger(height) || height <= 0) {
    throw new RangeError("width and height must be positive integers");
  }

  const image = new Image();
  image.src = svgUrl;
  await image.decode();

  const canvas = document.createElement("canvas");
  canvas.width = width;
  canvas.height = height;

  const context = canvas.getContext("2d");
  if (!context) throw new Error("Could not create a 2D canvas context");
  context.drawImage(image, 0, 0, width, height);

  return new Promise((resolve, reject) => {
    canvas.toBlob((blob) => {
      if (blob) resolve(blob);
      else reject(new Error("PNG encoding failed"));
    }, "image/png");
  });
}

async function downloadSvgAsPng(svgUrl, width, height) {
  const blob = await svgToPngBlob(svgUrl, width, height);
  const objectUrl = URL.createObjectURL(blob);
  const link = document.createElement("a");
  link.href = objectUrl;
  link.download = "image.png";
  link.click();
  setTimeout(() => URL.revokeObjectURL(objectUrl), 1000);
}

// Example: downloadSvgAsPng("/images/logo.svg", 1200, 600);

Put the functions in a script loaded by the page, then call downloadSvgAsPng() in response to a user action, such as a button click. The SVG URL must be one the browser can load. MDN’s Canvas API guidance emphasizes waiting for the image before calling drawImage(); image.decode() provides that wait here. MDN describes toBlob() as creating a Blob representing the image in the canvas. PNG is a required output format for this method.

Use a button instead of downloading on page load

<button id="export">Download PNG</button>
<script>
  document.querySelector("#export").addEventListener("click", async () => {
    try {
      await downloadSvgAsPng("/images/logo.svg", 1200, 600);
    } catch (error) {
      console.error("Could not export SVG:", error);
      alert("PNG export failed. Check the SVG URL and browser console.");
    }
  });
</script>

Handling the returned promise matters: a missing asset, decode error, canvas failure, or blocked export will reject or otherwise fail, and should not be silently reported as a successful download.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Choose output size without distorting the SVG

canvas.width and canvas.height are the output bitmap’s pixel dimensions. They are not CSS display sizes. An SVG drawn into a canvas whose proportions differ from the SVG’s will be stretched by drawImage(image, 0, 0, width, height).

For example, if the SVG’s intended ratio is 2:1, a 1200 × 600 canvas preserves it; a 1200 × 1200 canvas does not. Choose dimensions in the same ratio as the SVG’s viewBox or intended intrinsic size. If you need a square image from a wide SVG, decide whether to crop, add empty space, or accept distortion; merely changing the canvas dimensions does not make that design decision for you.

SVG files with only a viewBox

For this image-loading workflow, MDN’s canvas image tutorial says the SVG should specify root width and height. A viewBox defines the SVG’s coordinate system and proportions, but do not assume that a CSS layout size elsewhere on the page will automatically become the exported bitmap size. Add suitable root dimensions to the SVG when possible, then independently set the desired output pixel dimensions on the canvas.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

If you control the SVG text but it has no intrinsic dimensions, you can create an SVG Blob after adding explicit dimensions to its root element, then load that Blob as the image source. Ensure that the chosen dimensions reflect the intended aspect ratio. For complex or untrusted SVG text, avoid blindly rewriting markup with string substitutions; use a controlled asset or an SVG-aware parser.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How the browser conversion works

  1. Load the SVG as an image. Assign its URL to an Image object. Do not draw immediately; wait for decoding to finish.
  2. Create the output surface. Set the canvas width and height to the pixel dimensions required for the PNG.
  3. Rasterize the SVG. Call drawImage() to paint the rendered image into the canvas.
  4. Encode the canvas. Call toBlob(callback, "image/png") to get binary PNG data.
  5. Use or download the result. Create an object URL for the Blob, attach it to a download link, and revoke the URL when it is no longer needed.

The canvas is the rasterization step: once drawn, the SVG’s vector shapes become pixels at the chosen output size. The resulting Blob is convenient for downloads or for uploading to another service. MDN also documents canvas.toDataURL("image/png"), which returns an encoded string rather than a Blob. Use that when a data URI is specifically needed; for file handling, a Blob avoids turning the entire image into a long text string.

Cross-origin images, fonts, and other dependencies

A browser may display an image from another origin but still forbid reading pixels from a canvas containing it. When cross-origin image content is drawn without the server’s required CORS permission, the canvas becomes tainted; calling toBlob() or toDataURL() can then throw a SecurityError. Setting image.crossOrigin = "anonymous" is not a workaround by itself: the remote server must return suitable CORS permission, and the property must be set before assigning the image URL.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

SVGs can also refer to external images, fonts, or other resources. SVG loaded in an image context has restrictions on external resource loading; MDN notes that such resources cannot be loaded there unless inlined as data URLs. Missing dependencies may therefore yield a PNG that looks different from the SVG as displayed in a full web page. For predictable results, prefer a self-contained SVG, inline its required assets where appropriate, or use resources served from the same origin. Confirm fonts and other rendering dependencies are available before exporting.

Or skip the browser setup

If the SVG is already rendered on a publicly reachable web page, ScreenshotNeo can capture that page as an image. This is a webpage screenshot, not a direct converter for an arbitrary SVG file; it is useful when what you need is a raster capture of the page showing the SVG.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s free plan to try it without a payment card.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Use Inkscape for local or batch conversion

If the SVG is a local file or conversion belongs in a build pipeline, Inkscape documents a command-line export route:

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

Inkscape also supports exporting selected SVG object IDs and batch processing. Command-line options can vary by installed version, so check the manual for that version before automating a larger job. The browser canvas route is suited to converting an SVG already available to a page; the CLI route is suited to local files and repeatable processing outside the browser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting failed or unexpected exports

  • The downloaded file is blank or the drawing is missing: Confirm the image loaded and decoded before drawing. Check the SVG URL, inspect the browser console, and verify the SVG root dimensions. If the image uses external resources, inline or make those dependencies available in a form supported by the image context.
  • toBlob() throws SecurityError: Look for cross-origin images or other content in the canvas. Serve the asset from the same origin, inline it, or configure the remote server to permit the required CORS access. A client-side crossOrigin setting cannot grant server permission.
  • The PNG is stretched: The output canvas ratio differs from the SVG’s intended ratio. Choose width and height that preserve the source proportions, or deliberately implement a crop or padding strategy.
  • The PNG is the wrong size: Set the canvas’s intrinsic width and height to the desired pixel dimensions. CSS sizing of the canvas element does not substitute for setting those bitmap dimensions.
  • The export fails before encoding: Catch errors from image.decode() and verify the URL is valid and accessible. Check that a 2D context was created and handle a null Blob callback result rather than creating a download from it.
  • The appearance differs from the page: The SVG may rely on external fonts or assets unavailable in image context. Make dependencies self-contained and verify that the export path renders them before relying on the output.

Performance and reliability considerations

The canvas holds a bitmap whose memory use grows with its pixel area, so extremely large output dimensions can consume significant browser memory. Use the smallest dimensions that satisfy the intended use, and avoid repeatedly creating canvases or object URLs without releasing resources. Revoke each generated object URL after the download has had a chance to start.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

For a user-facing browser feature, present a clear loading or error state while the image decodes and the Blob is produced. If exports are frequent, process one at a time or otherwise manage resource use deliberately. A canvas conversion depends on browser rendering and access permissions; it is not equivalent to a guaranteed server-side batch conversion pipeline.

Frequently Asked Questions

Does converting an SVG to PNG reduce its scalability?

Yes. The exported PNG is a raster image with fixed pixel dimensions; retain the original SVG when you need resolution-independent artwork.

What does the PNG resolution metadata mean here?

MDN describes canvas export formats that support resolution metadata as using 96 dpi. The pixel width and height remain the practical dimensions to choose for screen use.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I convert an SVG without displaying it on the page?

Yes. The image can be loaded and drawn to a canvas without being inserted into the visible document, provided the browser can load its SVG and permitted dependencies.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.