Tuesday, March 11, 2014

SVGFig, a pure Python SVG library

By Vasudev Ram


SVGFig is a pure Python library to generate and manipulate SVG images.

I came across it recently and tried it out a little.

Here's an example program I wrote, that uses SVGFig to generate a series of overlapping squares as an SVG image:

# test_svgfig.py
from svgfig import *

svgs = []
colors = [ "red", "green", "blue" ]

for x in range(10, 400, 50):
    y = x
    for j in range(3):
        svg = SVG("rect", x=x + 20 * j, y=y + 20 * j, \
            width=100, height=100, fill=colors[j])
        svgs.append(svg)

g = SVG("g", *svgs, fill_opacity="50%")
print g.xml()

I ran it with the command: python test_svgfig.py

That gave the output shown in the screenshot below (click image to enlarge):



- Vasudev Ram - Dancing Bison Enterprises

Contact Page

No comments: