PNG to SVG

Published Updated

Embed a PNG inside an SVG file. The pixels stay a bitmap, so this wraps the image and does not trace it into vector shapes.

This wraps your PNG. It does not vectorize it.

The output is an svg element with your PNG's width, height and viewBox, containing a single image element whose href is a data:image/png;base64,... string. Open the source viewer after converting and you will see exactly that. Nothing is redrawn, and the picture stays a bitmap.

Scaling the SVG up therefore blurs it, just as scaling the PNG would. A real file would stay sharp at any size, but making one from a bitmap is a different job called tracing.

What the wrapper costs

Base64 turns each 3 bytes into 4 characters, and the wrapper adds a few hundred bytes. Approximate SVG sizes:

PNG sizeBase64 textSVG file (about)
10,000 bytes13,33613.5 KB
100,000 bytes133,336133.5 KB
1,000,000 bytes1,333,3361.33 MB

Pick it when

A wrapped PNG is the right answer in a few cases.

  • A form or CMS accepts only .svg and you have only a bitmap.
  • You want one file that carries its picture and renders without a second request.
  • You are placing a bitmap into a vector document and need it embedded, not linked.

Wrapping a PNG in an SVG

  1. Step 1

    Add a PNG

    Pick one PNG file. The preview and its pixel size confirm that the browser can open it.

  2. Step 2

    Press Convert to SVG

    The page builds a small SVG document around your original file and shows the size of the new file.

  3. Step 3

    Download or read the source

    Save the .svg, or open the source viewer to see the markup that was written.

When you need real vectors

For cutting machines, logo cleanup, recoloring or printing at any size, trace the image instead. Potrace is a widely used tracer, and Inkscape's Trace Bitmap tutorial covers the same job in a desktop editor. Tracing works best on flat, high-contrast art, and photos rarely trace well.

The SVG 2 specification deprecates the XLink form of the link attribute in favor of plain href, which is what this file uses.

The method in four lines

The browser reads your PNG as a data URL, which is the file's bytes in Base64 behind a short prefix. It also loads the picture once to learn its pixel width and height. The tool then fills a fixed template: an XML line, an svg element with that width, height and viewBox, and one image element whose href holds the data URL. The text is saved as image/svg+xml.

Base64 turns every group of 3 input bytes into 4 characters (RFC 4648), so the picture grows by a third before the template is added. The SVG specification says an image element can refer to PNG or JPEG files, and that viewers have to support at least PNG, JPEG and SVG (SVG 2, embedded content). The same specification lists xlink:href among deprecated attributes, and href is the attribute this tool writes (MDN, the image element).

Worked example: four generated PNGs, 1200 x 800

These PNGs are synthetic and were made by a script: a flat five-color logo, a disc with a soft shadow (with transparency), a page of small text, and a photo-like gradient with grain. The template function was copied from the tool's component and run in Node 22 on each file. Afterwards the Base64 text was taken back out of each SVG and its SHA-256 hash compared with the hash of the original PNG.

Test PNGPNG sizeBase64 textSVG fileSVG / PNG
Flat logo7,827 B10,436 chars10,639 B1.359
Disc with soft shadow47,538 B63,384 chars63,587 B1.338
Page of small text141,587 B188,784 chars188,987 B1.335
Photo-like gradient1,812,977 B2,417,304 chars2,417,507 B1.333

In all four runs the hash of the embedded bytes matched the hash of the PNG, so the picture inside the SVG is the file you gave the tool, not a re-encoded copy. The Base64 length equals 4 times the PNG size divided by 3, rounded up, and the template, including the data URL prefix, added 203 bytes. The ratio therefore falls toward 1.333 as files get bigger and is worst for tiny images, where the 203 bytes matter.

Edge cases and limits

  • Only the PNG file type is offered in the picker. A file that the browser cannot open as an image never reaches the template step.
  • The whole SVG is built as one text string in memory. For the 1.8 MB test PNG that is a 2.4 MB string, which is no problem on a desktop, but a very large PNG makes a string a third larger than the file.
  • Width and height come from the decoded image. A PNG with a pixel density tag is not rescaled, so the SVG is as many user units wide as the PNG has pixels.
  • Because the picture is a bitmap, the SVG cannot be recolored with CSS and its shapes cannot be edited. The tool itself does no compression.

Wrapped, not redrawn: nine PNGs in three browsers

We ran the converter component from this page in Google Chrome 157, Firefox 155 and Playwright's WebKit build (not the Safari app) on nine PNGs generated by a script, picked for the formats that trip converters up: 16 bits per channel, Adam7 interlacing, a palette with a transparent entry, grayscale, soft transparency, a 144 dpi density tag, a gamma 1.0 tag, a single pixel and a 3000 x 2000 photo-like picture. For each SVG we took the Base64 text back out and compared its SHA-256 hash with the file's, then let the same browser draw the SVG and the PNG at their own size and compared the two pixel by pixel.

Test PNGPNG sizeSVG sizePixels that differ, SVG vs PNG
8-bit RGBA with soft edges, 400 x 30016,506 B22,208 B0 of 120,000
16 bits per channel, 256 x 256327,319 B436,628 B0 of 65,536
Palette with a transparent entry, 200 x 1201,468 B2,160 B0 of 24,000
Adam7 interlaced, 300 x 200168,160 B224,416 B0 of 60,000
Grayscale ramp, 256 x 100524 B900 B0 of 25,600
144 dpi density tag, 300 x 200165,418 B220,760 B0 of 60,000
Gamma 1.0 tag, 300 x 200165,413 B220,752 B0 of 60,000
A single pixel69 B280 B0 of 1
Photo-like, 3000 x 200011,806,419 B15,742,098 B0 of 6,000,000

The three engines wrote SVGs of the same size to the byte, every embedded payload hashed to the original file, and every SVG drew exactly the pixels of its PNG: zero differences in all 27 comparisons. The width and height are the PNG's pixel size even for the 144 dpi file (width="300" height="200"), and each engine drew it at 300 x 200. The template around the Base64 text came to 188 bytes for the single pixel, 200 bytes for the three-digit sizes and 206 bytes for 3000 x 2000, because the width and height are each written three times.

Building the 15,742,098-byte SVG for the 3000 x 2000 file took a median of 19 ms in Chrome 157, 15 ms in Firefox 155 and 18 ms in the WebKit build, from pressing Convert to SVG to the download link (5 runs).

Files that are not quite PNGs

  • A JPEG renamed to .png is accepted and wrapped as it is: the data URL says image/png but carries the JPEG bytes, and all three engines still drew it with no pixel changed.
  • The file picker offers PNG files, but the drop area takes any file that is not empty. A dropped JPEG is wrapped with a data:image/jpeg URL, and a file with no type, for example one without an extension, with data:application/octet-stream; all three engines drew both with no pixel changed.
  • A text file named .png is refused in all three engines with "Couldn't read this image. It may be damaged, or not an image your browser can open."

Questions about PNG to SVG

Does this trace my PNG into vector shapes?

No. The PNG is stored unchanged inside the SVG as a Base64 image. The picture is still made of pixels, so it blurs when enlarged, and you cannot edit individual shapes or colors.

Why is the SVG bigger than my PNG?

Base64 writes every 3 bytes of the PNG as 4 characters, which adds a third. A 300,000-byte PNG becomes about 400,000 bytes of SVG text before the small wrapper. Nothing is compressed further.

Why does my Cricut, laser cutter or embroidery software reject or misread the file?

Those programs follow outlines, and this file has none. Use a tracer such as Potrace or Inkscape's Trace Bitmap to turn the picture into paths, then check the result by eye.

The image is blank in my older editor. What is wrong?

The file points to its picture with a plain href attribute, which is the SVG 2 form. SVG 1.1 used xlink:href, and some older programs only read that. Current browsers read both.

Is transparency kept?

Yes. The original PNG bytes are embedded as they are, so the alpha channel and the pixel size are identical.

What is this useful for, then?

Filling a slot that only takes .svg files, putting a bitmap into an SVG-only workflow, or keeping a picture and its markup in one self-contained file, for example to paste inline into HTML.

Is the picture inside the SVG the same file as my PNG?

In our test, yes. We took the Base64 text back out of SVGs made from four generated PNGs and the SHA-256 hash matched the original file each time.

How much bigger will the SVG be?

About a third, plus about 200 bytes. In our four test files the SVG was 1.333 to 1.359 times the PNG size, the higher value for a 7.8 KB file.

Can I run the SVG through an SVG optimizer to make it smaller?

An optimizer that only tidies markup has little to remove, because almost all of the text is the Base64 picture. To shrink it, make the PNG smaller first, for example with the Image Compressor, and then wrap it.

Is a 16-bit or interlaced PNG kept as it is?

Yes. The 16-bit, interlaced, palette and grayscale test files were embedded byte for byte: the SHA-256 hash of each Base64 payload matched its file in Chrome 157, Firefox 155 and the WebKit build, and each SVG drew the same pixels as its PNG.

Does the SVG look different from the PNG in a browser?

No difference showed up. Drawn at its own size, each of the nine test SVGs gave zero differing pixels against its PNG drawn the same way, in all three engines, including the file with soft transparency and the one with a gamma 1.0 tag.

Will a 144 dpi PNG come out at half size?

No. The SVG takes the pixel size and leaves the density tag inside the embedded file: the 300 x 200 PNG tagged 144 dpi gave width="300", height="200" and viewBox="0 0 300 200", and all three engines drew it 300 x 200.

What happens if I drop a JPEG on the page?

It is wrapped as it is, as a data:image/jpeg URL inside the SVG, and all three engines drew it with no pixel changed. Only the file picker is limited to PNG; a text file renamed .png is refused with a "Couldn't read this image" message.

Related guide

JPG, PNG, WebP, HEIC and SVG: which image format to use. The guide separates wrapping a PNG in SVG from tracing a vector, and shows how vector size and pixel size differ.

Related Tools