[Image-SIG] Read SVG files - extracting the path

Fredrik Lundh fredrik at pythonware.com
Tue Nov 9 09:39:55 CET 2010


On Fri, Oct 8, 2010 at 6:59 PM, Sebastian Koblinger
<werwilldaswissen at chello.at> wrote:
> Hi everybody!
>
> I'm new to Python as well as to this mailing list and this is my question:
>
> Is it possible to read a path provided by an SVG file, and based on that path, make a selection of an image?
> (Further I'd like to invert the selection and fill it with black.)
>
> Is that doable with PIL?
>
> AFAIK ImagePath can create a path object, but is there a function, a module, or anything else that reads the path of the SVG directly?
> I rawly could imagine to read the SVG as a text file, scan it for the "path" argument, read the subsequent tuples and make them a path object.

You want an XML library (you could use e.g. xml.etree or lxml) to read
the SVG file itself.

Converting an SVG path to an image mask is a bit trickier, depending
on how many SVG features you want to support -- SVG paths support both
straight line segments and various curves.  The aggdraw add-on to PIL
(http://effbot.org/zone/aggdraw-index.htm) might be a better choice
than ImagePath; I'm not aware of any ready made SVG to raster
converter built on these tools, though.

Yet another alternative would be to look for some SVG rendering tool,
beyond GIMP.  No good pointers there, though, but maybe some other
image-sig:ers have some ideas.

</F>


More information about the Image-SIG mailing list