Render a white rectangle over an image with the composite operation

ctx.globalCompositeOperation = 'difference';

The amount of the effect can be controled with the alpha setting

// Render the image
ctx.globalCompositeOperation='source-atop';
ctx.drawImage(image, 0, 0);

// set the composite operation
ctx.globalCompositeOperation='difference';
ctx.fillStyle = "white";
ctx.globalAlpha = alpha;  // alpha 0 = no effect 1 = full effect
ctx.fillRect(0, 0, image.width, image.height);

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/15939917-5bdd-4f00-9b11-596c1c893a8f/Untitled.png