How to convert a JPEG image into SVG format using ImageMagick?
3 Answers
you'll need to use potrace and convert to a bitmap first.
$convert input.jpg output.ppm
$potrace -s output.ppm -o svgout.svg
-
1Great tool. Thanks for this tip. – kwoxer Jan 20 '15 at 06:11
-
7as a one-liner without intermediate file I used: `convert -channel RGB -compress None input.jpg bmp:- | potrace -s - -o output.svg` – Louis Maddox Mar 17 '16 at 17:48
-
3Apart from Portable PixMap `.ppm`, Portable GrayMap `.pgm` and even Portable Bitmap `.pbm` can also be used as intermediate file type. [Here](https://en.wikipedia.org/wiki/Netpbm_format) is more information. – Serge Stroobandt Sep 27 '17 at 11:48
-
This seems to answer the question and should be selected as the most appropriate answer yet. – Saif Ul Islam Mar 21 '21 at 03:57
-
1Portrace does not support more than 2 colors :( – phoet Oct 17 '22 at 19:52
Actually, with a complete installation of a recent version of ImageMagick it should be as easy as:
convert some.jpeg some.svg
Of course, ImageMagick cannot do it all by itself -- it uses delegates (helper programs) to handle SVG input or output. (This has been pointed out by other answers already.)
To see a (partial) list of all delegates (and their respective commands), run
convert -list delegate
To see the config file where all the delegate secrets hide, see
convert -list delegate | grep delegates.xml
To see a (partial) list of SVG handling delegates, run
convert -list delegate | grep -i svg
However, ImageMagick likes to put some of its external helper utilities into 'stealth' mode and doesn't necessarily reveal their presence when using above commands.
Just look into the delegates.xml
file itself. On my system it's:
grep -i svg /opt/local/etc/ImageMagick/delegates.xml | grep -i --color stealth
<delegate decode="autotrace" stealth="True" \
command=""/opt/local/bin/convert" "%i" \
"pnm:%u"\n\
"/opt/local/bin/autotrace" \
-input-format pnm \
-output-format svg \
-output-file "%o" "%u""/>
<delegate decode="svg:decode" stealth="True" \
command=""/opt/local/bin/inkscape" "%s" \
--export-png="%s" \
--export-dpi="%s" \
--export-background="%s" \
--export-background-opacity="%s" \
> "%s" 2>&1"/>
As you may see, on my system the ImageMagick installation automatically uses (amongst others)...
- ...
inkscape
to convert SVG to PNG; - ...
autotrace
to convert PNM to SVG;
Of course, one could argue the benefits of rather using autotrace
directly -- but that would require to manually convert the whatever-input-format to PNM first. So for this preliminary step you'd probably use ImageMagick anyway...

- 86,724
- 23
- 248
- 345
-
8When I tried this and opened the svg it simply embeded the png data into the svg xml. – Clintm Mar 02 '17 at 19:05
-
You'll actually need some software or code to vectorize your image in between, as jpg is a raster format, while SVG is a vector format. I don't think imagemagick alone can do that for you.

- 239,200
- 50
- 490
- 574

- 49,103
- 10
- 104
- 136
-
6+1: Turning a bunch of lines into a large matrix of pixels can be done fairly dumbly. Doing the reverse requires some fairly serious smarts. – T.E.D. Jul 15 '09 at 17:32