[Project_owners] Display images in greyscale?

Aron Rubin aronrubin at gmail.com
Mon Jan 22 19:18:40 PST 2007

On 1/21/07, Balaganesh Damodaran <bg.play at gmail.com> wrote:
> Er... I'm a total dunce when it somes to javascript so i'd appreciate a
> bit more detailed explanation of what exactly im supposed to do with the
> function...
> regards,
> bg
> Aron Rubin wrote:
> >// luminosity value from color components
> >function rgb2lum( r, g, b ) {
> >  return( (0.299/255.0)*r + (0.587/255.0)*g + (0.114/255.0)*b );
> >}
> >
> >On 1/19/07, Balaganesh Damodaran <bg.play at gmail.com> wrote:
> >
> >
> >>Hi guys,
> >>    I need to force firefox into displaying any image on any page in
> >>greyscale. Is there any way to do this???
> >>Regards,
> >>bg
> >>

The only way I know to do this would be to use the canvas image
element. I don't think you can access the pixel data from the w3c DOM.
You would use getImageData() to get the pixels (image data). For each
pixel get the luminance (with the supplied function and then set each
color channel to the luminance. Then you would use setImageData() to
write the pixels back out.



More information about the Project_owners mailing list