How to apply SVG Filter to Group using svgwrite with Python?
Question: Does anybody have an example of how to apply SVG filter to a SVG group using
svgwrite?

Here's what I'm trying to do:

    
    
    import svgwrite
    
    dwg = svgwrite.Drawing('test.svg', profile='full')
    grp = dwg.g()
    grp.add(dwg.rect(insert=(5,5),size=(20,20)))
    
    filtr = dwg.defs.add( dwg.filter(id="Ga",filterUnits="userSpaceOnUse") )
    feGauss = filtr.feGaussianBlur()
    
    grp.filter = feGauss   # This does not work
    dwg.add(grp)
    dwg.save()
    

The result does not pass filter onto the group as expected.

    
    
    >>> dwg.tostring()
    u'<svg baseProfile="full" height="100%" version="1.1" width="100%"     xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink"><defs /><g><rect height="20" width="20" x="5" y="5" /></g></svg>'
    

Any help is highly appreciated!


Answer: Below is an example of using a simple blur filter on a group with a single
rectangle. More of my svgwrite examples can be found at
<https://docs.google.com/folder/d/0BwFQiTKfux0qY1Y2d1hRdndtSEk/edit>

    
    
    #!/usr/bin/python3
    # License: MIT
    import svgwrite
    
    progname = 'example_filter_on_group'
    
    def create_svg(name):
    
        svg_size_w = 900
        svg_size_h = 1500
        title_size = 20
        y = 0
        title = name + ': example of filter on a group'
        dwg = svgwrite.Drawing(name, (svg_size_w, svg_size_h), debug=True)
        # background will be white.
        dwg.add(dwg.rect(insert=(0, 0), size=('100%', '100%'), fill='white'))
    
        # create simple filter to blur rectangle
        blur6_filter = dwg.defs.add(dwg.filter())
        blur6_filter.feGaussianBlur(in_='SourceGraphic', stdDeviation=6)
    
        # group with filter
        g_f = dwg.add(dwg.g(filter=blur6_filter.get_funciri()))
        g_f.add( dwg.rect(insert=(50, 50), size=(50, 50), fill='aqua'))
    
        dwg.save()
    
    if __name__ == '__main__':
        create_svg(progname + '.svg')
    

  * Lawrence

