Reputation: 395
The simplest method possible is preferable. I unfortunately don't know much about image manipulation!
Upvotes: 1
Views: 5538
Reputation: 54026
You can use the globalCompositeOperation
,"hue"
,"saturation"
,"color"
, and "luminosity"
Where
For example if you want to change the image saturation to full saturation
ctx.drawImage(image,0,0); // image to change
ctx.globalCompositeOperation = "saturation";
ctx.fillStyle = "hsl(0,100%,50%)"; // saturation at 100%
ctx.fillRect(0,0,image.width,image.height); // apply the comp filter
ctx.globalCompositeOperation = "source-over"; // restore default comp
If you want finer control you will have to do it pixel by pixel using getImageData
and setimagedata
but this can be very slow. For speed you are best to use a webGL filter that will compare to the above comp modes in terms of speed, but the trade off is code complexity.
Upvotes: 3