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

The ability to reference SVG graphics in a filter #887

Closed
scottkellum opened this issue Jun 8, 2022 · 2 comments
Closed

The ability to reference SVG graphics in a filter #887

scottkellum opened this issue Jun 8, 2022 · 2 comments

Comments

@scottkellum
Copy link

I would like the ability to reference a graphic to use within an SVG filter. For example, a repeating star pattern that can be applied to text effects, or a gradient to be used as a displacement. Currently the only way I can think to do this is by using feImage. Maybe having a place for vector paths to be stored in <defs> similar to how linearGradient works, with the addition of a method to pull those definitions into a filter for use.

@BigBadaboom
Copy link
Contributor

There is a way. Just use feImage.

You might be under the impression that feImage can only point to an external image. That's not the case.

<svg viewBox="0 0 250 250">
  <defs>
    <filter id="Image" x="0" y="0" width="250" height="250">
      <feImage xlink:href="#smiley" />
    </filter>
    
    <g id="smiley">
      <circle cx="125" cy="125" r="100" fill="yellow"/>
      <circle cx="90" cy="100" r="10" fill="black"/>
      <circle cx="160" cy="100" r="10" fill="black"/>
      <circle cx="125" cy="110" r="70"
              fill="none" stroke="black" stroke-width="4"
              stroke-dasharray="130 1000" stroke-dashoffset="-40"/>
    </g>
  </defs>
  
  <rect x="0"  y="0" width="250" height="250" filter="url(#Image)"/>
</svg>

See: https://jsfiddle.net/r462w7eq/

@scottkellum
Copy link
Author

@BigBadaboom
Thank you! I’ve spent way too much time trying to get this working assuming Firefox would have a feature like this. It looks like the only browser it works in is Chrome…

This is exactly what I was looking for (and what I had tried) so thank you! I hope it gets implemented cross browser soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants