MWE using Gaussian blur filter #96
Answered
by
cduck
enricofacca
asked this question in
Q&A
-
Can someone provide a Minimal Working Example where a Gaussian filter is applied to blur the edges of a shape? I tried using the Filter and FilterItem classes but I did not succeed. Thank you in advance. Enrico |
Beta Was this translation helpful? Give feedback.
Answered by
cduck
Apr 17, 2023
Replies: 1 comment 1 reply
-
This is a good question. Filters can be a bit tricky. Here is that example translated to drawsvg: d = draw.Drawing(230, 120)
# Circle
d.append(draw.Circle(60, 60, 50, fill='green'))
# Blurred circle
blur = draw.Filter()
blur.append(draw.FilterItem('feGaussianBlur', in_='SourceGraphic', stdDeviation=5))
d.append(draw.Circle(170, 60, 50, fill='green', filter=blur))
d.save_svg('out.svg')
d SVG file content (from <?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="230" height="120" viewBox="0 0 230 120">
<defs>
<filter id="d0">
<feGaussianBlur in="SourceGraphic" stdDeviation="5"></feGaussianBlur>
</filter>
</defs>
<circle cx="60" cy="60" r="50" fill="green" />
<circle cx="170" cy="60" r="50" fill="green" filter="url(#d0)" />
</svg> Notes:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
cduck
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a good question. Filters can be a bit tricky. Here is that example translated to drawsvg:
SVG file content (from
print(d.as_svg())
):