My challenge is to add color filter to dark part of image and another color filter to light part of image. To achieve effect like this https://i.stack.imgur.com/niAKW.jpg
I am using canvas with globalCompositeOperation effects, but I am able to apply only one filter without affect the other one.
ctx.drawImage(image, 0, 0, 380, 540);
ctx.globalCompositeOperation = 'darken';
ctx.fillStyle = overlayFillColor;
ctx.fillRect(0, 0, 380, 540);
this works great to apply color filter to dark or light areas, based on the globalCompositeOperation, but if I add another filter, it change colors of the previous filter as well.
any idea?
thanks Ales
There is a nice SVG filter component which does map luminance to alpha:
<feColorMatrix type="luminanceToAlpha"/>Since we can use SVG filters in canvas, this allows us to separate the dark area from the light one and use compositing instead of blending.
This way, your input colors are preserved.
Note that hopefully we'll have CanvasFilters objects in a near future, which will make SVG filters to canvas easier to use, and accessible in Workers (they currently aren't...). So for the ones from the future (or from the present on Canary with web-features flag on), this would look like: