Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a filter #37

Closed
konstare opened this issue Jan 4, 2021 · 4 comments
Closed

How to add a filter #37

konstare opened this issue Jan 4, 2021 · 4 comments

Comments

@konstare
Copy link

konstare commented Jan 4, 2021

Hey,

Could you help me please. I cannot understand how to add a filter to the svg Document. Is it possible with your library? For example, I want to add feGaussianBlur. As I understand i should start something like this:

let filter = Filter::new().add(What exactly I should put here??);
let definitions = Definitions::new().add(filter);
let document = Document::new()
    .set("viewBox", (0, 0, 70, 70))
    .add(definitions)
........
@IvanUkhov
Copy link
Member

IvanUkhov commented Jan 5, 2021

Hi, do you have a brief example in SVG?

@konstare
Copy link
Author

konstare commented Jan 5, 2021

Sure, I would like to write something like this:

 <svg height="110" width="110">
  <defs>
    <filter id="f1" x="0" y="0">
      <feGaussianBlur in="SourceGraphic" stdDeviation="15" />
    </filter>
  </defs>
  <rect width="90" height="90" filter="url(#f1)" />
</svg> 

@IvanUkhov
Copy link
Member

IvanUkhov commented Jan 5, 2021

You see you have to append an feGaussianBlur to a filter. There is no dedicated struct for feGaussianBlur:

https://docs.rs/svg/0.8.0/svg/node/element/index.html

What you can do instead is to append Element("feGaussianBlur").

@konstare
Copy link
Author

konstare commented Jan 5, 2021

Thank you. It works. I did not figure out that there is a structure Element by itself.

@konstare konstare closed this as completed Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants