Image to SVG conversion with Python

C

Carlo DiCelico

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
 
D

Dave Angel

Carlo said:
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
formats.

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 http://code.activestate.com/recipes/325823/ )

Then you might want to use ( http://www.imagemagick.org/script/index.php
) to convert it to jpg or other format.

DaveA
 
C

Carlo DiCelico

I have no direct experience with SVG, but have used and analyzed other
formats.

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 usinghttp://code.activestate.com/recipes/325823/)

Then you might want to use (http://www.imagemagick.org/script/index.php
) to convert it to jpg or other format.

DaveA

Thanks, this makes perfect sense.
 
N

Nobody

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?

JPEG/PNG are raster formats, SVG is a vector format.

To convert raster graphics to vector graphics, you need a "tracing"
program (aka "image tracing", "vector tracing", "vectorizing"), e.g.
potrace (this program is often bundled with InkScape):

http://potrace.sourceforge.net/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top