Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to recolor an image using JavaScript? [duplicate]

I was wondering if anyone knew of a way to recolor an image using JavaScript. Any type of access to an image's pixels would work, I suppose, as long I could read/write color values. It should work in Firefox; if it doesn't work in IE, no big deal, but it would be a benefit if it did.

Thank you for your help!

like image 303
Chris Laplante Avatar asked Feb 27 '23 04:02

Chris Laplante


2 Answers

You could change the image using canvas.

There are dozens of examples online of changing images to grayscale. There shouldn't be any reason you can't change the colours to something different.

like image 103
alex Avatar answered Mar 15 '23 08:03

alex


In addition to alex's answer (eg: to use <canvas>, which is not yet widely supported - cough IE cough), you can use JS to change an image to another and give the illusion that it's just the same image, recolored. The other image can be readily available or can be created by the server on the fly if your server-side language supports image manipulation (eg: PHP can do it with GD).

like image 40
NullUserException Avatar answered Mar 15 '23 08:03

NullUserException