Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blend mode:multiply in Internet Explorer

I need to have an Image blended together with an red square in mode multiply. As I know, IE and Safari doesn't support the css-property "blend-mode", so I tried it with blending them together in a canvas and everything worked fine - except in IE. Is there any way to get those blended together in IE or isn't that supported yet?

like image 337
Dominik Seemayr Avatar asked Aug 06 '14 11:08

Dominik Seemayr


People also ask

What is mix-blend-mode Multiply?

normal : this attribute applies no blending whatsoever. multiply : the element is multiplied by the background and replaces the background color. The resulting color is always as dark as the background. screen : multiplies the background and the content then complements the result.

Why is mix-blend-mode not working?

💡 If you find your CSS mix-blend-mode not working as expected (on a white background), you need to explicitly set a background-color on the underlying element. The easiest way to do so is to apply background-color: white; on the html and body elements.

What does mix-blend-mode screen do?

The mix-blend-mode CSS property sets how an element's content should blend with the content of the element's parent and the element's background.


1 Answers

For Internet Explorer, Canvas blending modes are "under consideration".

https://developer.microsoft.com/en-us/microsoft-edge/platform/status/mixblendmode/?q=blend

Until blends are implemented in IE, you can roll-your-own multiply filter:

function multiply(R, G, B) {
  var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
  var data = imgData.data;

  for (var i = 0; i < data.length; i += 4) {
    data[i    ] = R * data[i    ] / 255;
    data[i + 1] = G * data[i + 1] / 255;
    data[i + 2] = B * data[i + 2] / 255;
  }

  ctx.putImageData(imgData, 0, 0);
}

And this multiply image filter is cross-browser compatible too.

like image 151
markE Avatar answered Sep 26 '22 20:09

markE