How to Convert Base64 SVG to Vector Paths
This article covers the most effective methods for converting
embedded base64 raster images within an SVG file back into native,
scalable vector paths. When an SVG contains a base64-encoded PNG or JPEG
inside an <image> tag, it loses the infinite
scalability and small footprint of true vector graphics. Below, you will
find direct solutions to extract the raster data and trace it back into
vector geometry using vector graphics software, command-line utilities,
programmatic scripts, and browser-based tools.
1. Vector Graphic Editors (GUI Tracing)
Desktop vector editors offer interactive tracing engines with real-time previews to adjust thresholding, smoothing, and color layers.
Inkscape (Free & Open Source)
- Open the SVG file containing the base64 image in Inkscape.
- Select the embedded image on the canvas.
- Navigate to Path > Trace Bitmap (or press
Shift + Alt + B). - Choose a detection mode:
- Brightness Cutoff or Edge Detection for monochrome/black-and-white graphics.
- Color Scans or Autotrace for multi-colored artwork.
- Click Apply. Inkscape places the newly generated
<path>objects directly over the raster image. - Delete the underlying raster image element and save the SVG.
Adobe Illustrator
- Open the SVG in Illustrator and select the embedded image.
- Open the Image Trace panel (Window > Image Trace).
- Select a preset (such as Silhouettes, Black and White Logo, or High Color).
- Click Expand in the top control bar to commit the trace and convert the live preview into editable vector paths.
- Delete the original linked or embedded pixel data and re-export the file.
2. Command-Line Tracing Utilities
For batch processing or headless environments, command-line vectorizers can process extracted base64 assets quickly.
Potrace
Potrace is a standard algorithm for tracing monochrome bitmaps. 1.
Extract the base64 string from the SVG’s xlink:href or
href attribute. 2. Decode the base64 string into a bitmap
format (such as .pbm, .pgm, or
.bmp). 3. Run Potrace:
bash potrace input.bmp -s -o output.svg 4. Replace the
original <image> node in your master SVG with the
<path> or <g> elements from
output.svg.
VTracer
VTracer supports full-color vectorization without requiring
multi-pass monochromatic layers. 1. Decode the base64 string to a
.png or .jpg. 2. Run VTracer:
bash vtracer --input input.png --output output.svg --colormode color
3. Automated Programmatic Pipelines (Python)
You can automate the entire lifecycle—parsing the SVG, decoding base64 nodes, vectorizing them, and replacing the nodes—using Python.
A standard script workflow follows these steps:
- Parse the XML: Use
xml.etree.ElementTreeorlxmlto locate all<image>elements withdata:image/...;base64,URIs. - Decode Data: Strip the URI prefix and decode the
base64 string into raw image bytes using Python’s
base64module. - Execute Vectorizer: Pass the byte array to a
tracing binding (such as
pypotraceorvtracer-python). - Swap Elements: Parse the generated SVG path strings
into XML nodes, insert them into the parent container of the SVG, and
remove the original
<image>element. - Serialize: Write the updated XML tree back to a clean SVG file.
4. Web-Based Tracing Tools
For single-file conversions without installing software:
- SVGcode: A Progressive Web App (PWA) that converts raster images directly to SVG in the browser using the Potrace engine. You can drag and drop your extracted base64 image and download the traced vector file.
- Vector Magic: A web-based converter capable of handling complex color gradients and multi-tone raster data with automated edge detection.