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 Vector. An image stored as drawing instructions (shapes, curves, fills) instead of pixels, so it can be drawn at any size without blur. SVG is the web's vector format. Read the guide 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 size | Base64 text | SVG file (about) |
|---|---|---|
| 10,000 bytes | 13,336 | 13.5 KB |
| 100,000 bytes | 133,336 | 133.5 KB |
| 1,000,000 bytes | 1,333,336 | 1.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
Step 1
Add a PNG
Pick one PNG file. The preview and its pixel size confirm that the browser can open it.
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.
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 PNG | PNG size | Base64 text | SVG file | SVG / PNG |
|---|---|---|---|---|
| Flat logo | 7,827 B | 10,436 chars | 10,639 B | 1.359 |
| Disc with soft shadow | 47,538 B | 63,384 chars | 63,587 B | 1.338 |
| Page of small text | 141,587 B | 188,784 chars | 188,987 B | 1.335 |
| Photo-like gradient | 1,812,977 B | 2,417,304 chars | 2,417,507 B | 1.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 PNG | PNG size | SVG size | Pixels that differ, SVG vs PNG |
|---|---|---|---|
| 8-bit RGBA with soft edges, 400 x 300 | 16,506 B | 22,208 B | 0 of 120,000 |
| 16 bits per channel, 256 x 256 | 327,319 B | 436,628 B | 0 of 65,536 |
| Palette with a transparent entry, 200 x 120 | 1,468 B | 2,160 B | 0 of 24,000 |
| Adam7 interlaced, 300 x 200 | 168,160 B | 224,416 B | 0 of 60,000 |
| Grayscale ramp, 256 x 100 | 524 B | 900 B | 0 of 25,600 |
| 144 dpi density tag, 300 x 200 | 165,418 B | 220,760 B | 0 of 60,000 |
| Gamma 1.0 tag, 300 x 200 | 165,413 B | 220,752 B | 0 of 60,000 |
| A single pixel | 69 B | 280 B | 0 of 1 |
| Photo-like, 3000 x 2000 | 11,806,419 B | 15,742,098 B | 0 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.