How to convert a PNG image to a SVG?
SvgPngSvg Problem Overview
How to convert a PNG image to a SVG?
Svg Solutions
Solution 1 - Svg
There is a website where you can upload your image, and see the result.
But if you want to download your svg-image, you need to register. (If you register, you get 2 images for free)
Solution 2 - Svg
potrace
does not support PNG as input file, but PNM.
Therefore, first convert
from PNG to PNM:
convert file.png file.pnm # PNG to PNM
potrace file.pnm -s -o file.svg # PNM to SVG
Explain options
potrace -s
=> Output file is SVGpotrace -o file.svg
=> Write output tofile.svg
Example
convert 2017.png 2017.pnm
Temporary file = 2017.pnm
potrace 2017.pnm -s -o 2017.svg
Script
ykarikos proposes a script png2svg.sh that I have improved:
#!/bin/bash
File_png="${1?:Usage: $0 file.png}"
if [[ ! -s "$File_png" ]]; then
echo >&2 "The first argument ($File_png)"
echo >&2 "must be a file having a size greater than zero"
( set -x ; ls -s "$File_png" )
exit 1
fi
File="${File_png%.*}"
convert "$File_png" "$File.pnm" # PNG to PNM
potrace "$File.pnm" -s -o "$File.svg" # PNM to SVG
rm "$File.pnm" # Remove PNM
One-line command
If you want to convert many files, you can also use the following one-line command:
( set -x ; for f_png in *.png ; do f="${f_png%.png}" ; convert "$f_png" "$f.pnm" && potrace "$f.pnm" -s -o "$f.svg" ; done )
See also
See also this good comparison of raster to vector converters on Wikipedia.
Solution 3 - Svg
A png is a bitmap image style and an SVG is a vector-based graphics design which supports bitmaps so it's not as if it would convert the image to vectors, just an image embedded in a vector-based format. You could do this using http://www.inkscape.org/ which is free. It would embed it, however it also has a Live Trace like engine which will try to convert it to paths if you wish (using potrace). See live trace in adobe illustrator (commericial) is an example:
http://graphicssoft.about.com/od/illustrator/ss/sflivetrace.htm
Solution 4 - Svg
You may want to look at potrace.
Solution 5 - Svg
Easy
- Download Inkscape (it's completely free)
- Follow the instructions in this short youtube video
As you'll see, if you want to do a whole lot of other clever .svg stuff you can do it using Inkscape also.
A non-technical observation: I personally prefer this method over "free" website offerings because, aside from often requiring registration, by uploading the image, in all practical terms, one is giving the image to the website owner.
Solution 6 - Svg
with adobe illustrator:
Open Adobe Illustrator. Click "File" and select "Open" to load the .PNG file into the program.Edit the image as needed before saving it as a .SVG file. Click "File" and select "Save As." Create a new file name or use the existing name. Make sure the selected file type is SVG. Choose a directory and click "Save" to save the file.
or
online converter http://image.online-convert.com/convert-to-svg
i prefer AI because you can make any changes needed
good luck
Solution 7 - Svg
To my surprise, potrace it turns out, can only process black and white. That may be fine for you use case, but some may consider lack of color tracing to be problematic.
Personally, I've had satisfactory results with Vector Magic
Still it's not perfect.
Solution 8 - Svg
A note to those using potrace and imagemagick, converting PNG images with transparency to PPM doesn't seem to work very well. Here is an example that uses the -flatten
flag on convert
to handle this:
sudo apt-get install potrace imagemagick
convert -flatten input.png output.ppm
potrace -s output.ppm -o output.svg
rm output.ppm
Another interesting phenomenon is that you can use PPM (256*3 colors, ie. RGB), PGM (256 colors, ie. grayscale) or PBM (2 colors, ie. white or black only) as the input format. From my limited observations, it would appear that on images which are anti-aliased, PPM and PGM (which produce identical SVGs as far as I can see) shrink the colored area and PBM expands the colored area (albeit only a little). Presumably this is the difference between a pixel > (256 / 2)
test and a pixel > 0
test. You can switch between the three by changing the file extension, ie. the following use PBM:
sudo apt-get install potrace imagemagick
convert -flatten input.png output.pbm
potrace -s output.pbm -o output.svg
rm output.pbm
Solution 9 - Svg
You can also try http://image.online-convert.com/convert-to-svg
I always use it for my needs.
Solution 10 - Svg
I just found this question and answers as I am trying to do the same thing! I did not want to use some of the other tools mentioned. (Don't want to give my email away, and don't want to pay). I found that Inkscape (v0.91) can do a pretty good job. This tutorial is quick to and easy to understand.
Its as simple as selecting your bitmap in Inkskape and Shift+Alt+B.
Solution 11 - Svg
Depending on why you want to convert from .png to .svg, you may not have to go through the trouble. Converting from .png (raster) to .svg (vector) can be a pain if you are not very familiar with the tools available, or if you are not a graphic designer by trade.
If someone sends you a large, high resolution file (e.g. 1024x1024), you can resize that down to pretty much any size you want in GIMP. Often, you will have problems resizing an image if the resolution (number of pixels per inch) is too low. To rectify this in GIMP, you can:
File -> Open
: your .png fileImage -> Image Properties
: check the Resolution, and the color space. You want a resolution around 300 ppi. In most cases you want the color space to be RGB.Image -> Mode
: set to RGBImage -> Scale Image
: leave the size alone, set and Y resolution to 300 or greater. Hit Scale.Image -> Scale Image
: the resolution should now be 300 and you can now resize the image down to pretty much any size you want.
Not as easy as resizing a .svg file, but definitely easier and faster than trying to convert a .png to a .svg, if you already have a big, high-resolution image.
Solution 12 - Svg
I'm assuming that you wish to write software to do this. To do it naively you would just find lines and set the vectors. To do it intelligently, you attempt to fit shapes onto the drawing (model fitting). Additionally, you should attempt to ascertain bitmaped regions (regions you can't model through shames or applying textures. I would not recommend going this route as that it will take quite a bit of time and require a bit of graphics and computer vision knowledge. However, the output will much and scale much better than your original output.
Solution 13 - Svg
http://online-converting.com/image/convert-to-svg/ worked well for converting to svg
Solution 14 - Svg
This tool is working very well right now.
Solution 15 - Svg
If you're on some Linux system, imagemagick is perfect. I.e
convert somefile.png somefile.svg
This works with heaps of different formats.
For other media such as videos and audio use (ffmpeg) I know you clearly stated png to svg, however; It's still media related.
ffmpeg -i somefile.mp3 somefile.ogg
Just a tip for if you wish to go through lots of files; a loop using basic shell tricks..
for f in *.jpg; do convert $f ${f%jpg}png; done
That removes the jpg and adds png which tells convert what you want.