canvas2D icon indicating copy to clipboard operation
canvas2D copied to clipboard

Make CSS filters work with `CanvasFilter`

Open tomayac opened this issue 3 years ago • 3 comments

Right now, there are two ways to provide filters: one for "simple" CSS filters (example: offscreenCanvas.filter = 'brightness(1)') and one for more complex SVG filters (example: offscreenCanvas.filter = new CanvasFilter([…])). Ideally, simple CSS filters could be modeled as {filter: 'brightness', amount: 1} as well, so they can all be passed in one big filter array.

tomayac avatar Nov 02 '21 14:11 tomayac

I wonder if passing the CSS strings directly in the filter property wouldn't be better here instead of "inventing" new properties which doesn't really map to anything (e.g what should be the properties for drop-shadow). So maybe something like the following could do?

new CanvasFilter([
  {
    filter: "convolveMatrix", 
    kernelMatrix: [ ... ]
  },
  {
    filter: "brightness(70%)"
  }
]);

cc @mysteryDate

Kaiido avatar Dec 04 '21 11:12 Kaiido

I wonder if passing the CSS strings directly in the filter property wouldn't be better[.]

This would work for me.

tomayac avatar Dec 06 '21 08:12 tomayac

@Kaiido I like that solution too, will be very easy to implement and test.

mysteryDate avatar Dec 07 '21 23:12 mysteryDate