I have been working with html canvas compositing trying to clip a pattern with a mask.
The main issue that I have is that the mask I have comes from an svg with transparencies within the outer most border. I want the entire inside from the outer most border to be filled with the pattern.
Take this SVG for example you can see that there is a single pixel border, then some transparency, and then an opaque red inner blob. The compositing I have done works as the documentation says it should, the single pixel border and the red inner portion pick up the pattern that I want to mask into this shape. The problem is that I want to mask the entire innards starting from the single pixel border.
This is where I think clip might help. But it seems clip only works with manually drawn paths, not paths from an svg (at least that I am aware of).
Is there a way to accomplish what I am trying to do?
Regards, James
The Path2D constructor accepts an SVG path data argument, that it will parse as the
d
attribute of an SVG<path>
element.You can then use this Path2D object with the
clip()
method:If you need to transform this path-data (e.g scale, or rotate), then you can create a second Path2D object, and use its
.addPath(path, matrix)
method to do so: