Image to SVG conversion with Python

Dave Angel davea at
Mon Nov 16 17:48:12 CET 2009

Carlo DiCelico wrote:
> I need to convert JPEG and PNG files to SVG. I'm currently using PIL
> to generate the JPEG/PNG files to begin with. However, I need to be
> able to scale the generated images up in size without a loss of image
> quality. Using SVG seems to be the best way to do this, other than
> generating the images in the maximum size/resolution in the first
> place, which would be too resource intensive.
> I've looked around online and have found some tools for creating SVGs
> but none for converting an image into SVG.
> Does anyone have any experience doing this? What would be the best way
> to go about this?
> Thanks,
> Carlo
I have no direct experience with SVG, but have used and analyzed other 

I expect it's unreasonable to convert jpg or png files to SVG.  The 
latter is a vector format, and can't efficiently represent pixels, which 
is all you have in the jpg files.  And even if you did it brute force, 
it still wouldn't scale any better than the original jpg.  If the jpg 
file was generated from lines, and wasn't too crowded, it *might* be 
possible to analyze it to reconstruct the vectors, but it would be both 
very slow, and inaccurate.

In Photoshop PSD files, you can have vector layers and RGB layers (plus 
other kinds).  You convert a vector layer (such as text) to bits by 
rasterizing (or flattening).  And once you do, it no longer scales 
cleanly.  For instance, when I'm sending composite images to a printer, 
I get much better quality sending the raster portion separate from the 
text, either as layers in a PSD file, or in a PDF file, or even as two 
separate files that they will merge later.  (In that case, I usually 
send a low-res flattened file, so they can see how it's supposed to look)

I'd say you should change your python code to generate the svg files 
first (perhaps using )

Then you might want to use ( 
) to convert it to jpg or other format.


More information about the Python-list mailing list