Image to SVG conversion with Python

Discussion in 'Python' started by Carlo DiCelico, Nov 16, 2009.

  1. 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
    Carlo DiCelico, Nov 16, 2009
    #1
    1. Advertising

  2. Carlo DiCelico

    Dave Angel Guest

    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
    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
    Dave Angel, Nov 16, 2009
    #2
    1. Advertising

  3. On Nov 16, 11:48 am, Dave Angel <> wrote:
    > 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
    > 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.
    Carlo DiCelico, Nov 16, 2009
    #3
  4. Carlo DiCelico

    Nobody Guest

    On Mon, 16 Nov 2009 07:19:49 -0800, 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?


    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/
    Nobody, Nov 16, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arne Nordmann
    Replies:
    0
    Views:
    503
    Arne Nordmann
    Jun 28, 2004
  2. Mardagg
    Replies:
    0
    Views:
    790
    Mardagg
    May 12, 2006
  3. Mardagg
    Replies:
    0
    Views:
    639
    Mardagg
    May 12, 2006
  4. milof83

    svg to svg saving problem

    milof83, Aug 18, 2006, in forum: Java
    Replies:
    1
    Views:
    800
    Roland de Ruiter
    Aug 18, 2006
  5. Helmut Jarausch

    Re: svg-chart 1.1 SVG Charting Library

    Helmut Jarausch, May 20, 2008, in forum: Python
    Replies:
    0
    Views:
    460
    Helmut Jarausch
    May 20, 2008
Loading...

Share This Page