CSS effect I want to achieve
css
img {
filter: sepia(1) saturate(4) hue-rotate(-42deg) invert(100%) grayscale(70%);
}
How does canvas implement the filter?This may require some knowledge of computer vision
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
const image = new Image();
image.src = "./1.jpg";
image.onload = function () {
context.drawImage(image, 0, 0, canvas.width, canvas.height);
const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
const data = imageData.data;
for (let i = 0; i < data.length; i += 4) {
// What should I do with this piece of code
// data[i] = 255 - data[i];
// data[i + 1] = 255 - data[i + 1];
// data[i + 2] = 255 - data[i + 2];
}
context.putImageData(imageData, 0, 0);
}