From pixels to shapes
A PNG, JPG or WebP file is a raster image, also called a bitmap: a grid of pixels, each with one color. An SVG file describes shapes instead. MDN describes SVG as an XML-based markup language for two-dimensional vector graphics that can be rendered at any size without loss of quality. That is why logos and icons are often wanted as SVG: they stay sharp on a large screen, in print and when you scale them in a design program.
This converter traces a raster image to vectorize it: it finds areas of the same color and writes their outlines as SVG paths. The result is a real SVG with shapes you can recolor, scale and edit. For when to use which format, read SVG vs PNG. For the other direction, use SVG to PNG.
How the tracing works
The tracing is done by imagetracer.js, a public domain library by Andras Jankovics. The steps, as its process overview describes them:
- Reduce the colors. Every pixel is assigned to one of a small number of colors with a variant of k-means clustering. This tool picks the starting colors itself with a median cut over the image, so a small accent color in a logo still gets its own color.
- Separate the layers. Each color becomes its own layer, and the edges between pixels of that color and other pixels are found.
- Follow the edges. The edge points are joined into closed outlines.
- Fit lines and curves. Each outline is replaced by straight lines and quadratic curves that stay within the error tolerance. Where neither fits, the outline is split and tried again.
- Write the SVG. Each color layer becomes a group of paths. This tool writes the largest areas first and the small details on top.
What each setting changes
| Setting | What it does | Try |
|---|---|---|
| Number of colors | How many color layers the image is reduced to | The real number of logo colors plus one for the background |
| Ignore specks | Drops outlines shorter than this many edge points | Raise it when dust or noise shows up as dots |
| Curve tolerance | Largest allowed distance, in pixels, between the outline and the fitted line or curve | Lower for sharp detail, higher for smooth and small files |
| Blur before tracing | Blurs the image with a radius of 1 to 5 pixels, but keeps pixels the blur would change a lot | 1 or 2 for JPEG files and scans |
| Trace size | Longest side of the image while it is traced | 1,000 px, or 1,600 px for fine detail |
| Remove white background | Leaves out every color whose red, green and blue are all 230 or higher | Logos on a white background |
The presets set these values for you. Logo, flat colors uses 6 colors. Black and white line art puts transparent areas on white and sorts every pixel into black or white, which suits drawings, signatures and stamps. To choose where gray turns black, make the image black and white first with the black and white image converter. Detailed uses 32 colors and a lower tolerance, which keeps more of a photo but makes a much larger file.
Worked example, computed with this tool: a 60 × 40 pixel image with a red square and a small blue dot on white, traced with the Logo settings and 3 colors, gives 3 color layers: white, red and blue. With Remove white background on, only the red and blue layers remain and the rest of the SVG is transparent.
What tracing can and cannot do
Tracing works best on images that already consist of flat areas: logos, icons, clip art, signatures, stamps, line drawings and scans of printed graphics with high contrast. Use the largest and cleanest file you have. A blurry or tiny image gives blobby shapes.
A photo does not become a true vector drawing. Soft shading turns into bands of flat color, and texture turns into thousands of small shapes. Small text is traced as shapes, not as text you can edit, and pixel art loses its square corners. A traced photo is often larger than the original file, because every shape is stored as text with its coordinates.
Tracing time grows with the number of pixels and colors. To keep it practical, the image is traced at the trace size you pick, at most 1,600 pixels on the longest side, and the SVG is then set to the width and height of your original image. Small images are enlarged up to four times before tracing, which smooths the stair steps of their edges. Tracing runs in a background thread, so the page stays usable. Very large photos may not open at all on an iPhone or iPad because of their memory limits.
How to use the PNG to SVG converter
- 1Drop an image on the box or tap it to choose one. HEIC photos from an iPhone work too.
- 2Pick a preset, then adjust the number of colors, specks, curve tolerance and blur while you watch the SVG next to the original.
- 3Turn on Remove white background if the design should sit on a transparent background.
- 4Press Download SVG, or Copy SVG code to paste it into HTML or a design tool.
Sources and credits
- imagetracer.js by Andras Jankovics, version 1.2.6, released into the public domain under the Unlicense. Its options documentation and process overview describe the settings and steps used here.
- The Unlicense: the public domain dedication of the library
- MDN Web Docs, SVG: Scalable Vector Graphics: definition of SVG and scaling without loss of quality
- W3C SVG 2, Paths: sections 9.3.4 to 9.3.7, the closepath, lineto and quadratic curve commands that the traced paths use
Related guides
- SVG vs PNG: When to Use Vector and When to Use Pixels
- Which Logo Files to Deliver: SVG, PNG, PDF and Favicon
- JPG vs PNG vs WebP vs AVIF: Which Format to Use
Frequently asked questions
Is my image uploaded?
No. Your browser opens the image, traces it in a background thread on your device and saves the SVG there. Nothing is sent to a server.
Will a photo become a real vector drawing?
Not in the sense of a drawing made by hand. The tracer splits the photo into a fixed number of color areas and outlines each one. You get an SVG made of shapes, but soft shading turns into flat bands and fine texture into many small shapes. Logos, icons and line art trace much better than photos.
Why is my SVG larger than the PNG?
Every shape is stored as text with its coordinates. A detailed image with many colors can need thousands of shapes, which takes more space than the compressed pixels of a PNG. Use fewer colors, raise Ignore specks or Curve tolerance, or pick a smaller trace size to get a smaller file.
How do I get a transparent background?
Turn on Remove white background. Every color layer that is close to white is left out of the SVG, so the background becomes transparent. White parts inside the design, such as white letters on a colored badge, are removed too. A PNG that is already transparent keeps its transparency without this switch.
Which setting gives the cleanest logo?
Start with the Logo preset and set Number of colors to the number of colors your logo really has, plus one for the background. If the edges look jagged, use a larger trace size. If small dots or noise appear, raise Ignore specks or add a little blur.
Why is the image scaled before tracing?
Tracing time grows with the number of pixels and the number of colors, so a 12-megapixel photo could take minutes. The image is traced at the trace size you choose, at most 1,600 pixels on the longest side, and the SVG is then set to the width and height of your original image. Small images are enlarged up to four times first, which gives smoother curves.