views:

60

answers:

4

Is there a way to display a color picture as greyscale using Html/Css? Ie. no server side processing.

Edited: monochrome -> greyscale

+1  A: 

The best way would be to upload a greyscale picture in the first place. If this is for some sort of hover task, take a look at creating a CSS sprite. I understand this doesn't answer the question fully, but I can't for the life of me understand why you need client side image manipulation.

m.edmondson
Lots of good solutions here but this one achieves what I'm looking for - no image swapping, no pixel manipulation, etc.
John Strickler
A: 

Try this out:

http://snipplr.com/view/2836/grayscale-img-with-css-crossbrowser/

Might be a good alternative...

Hope it helps!

Trufa
A: 

In addition to canvas, in at least some browsers (such as Firefox), you can use SVG filters. For an example, see this slide (button 2 invokes a filter that does pretty much what you want).

David Baron
A: 

I think i found another very good way with PHP!

Check this out:

<?php
$img = @imagecreatefromgif("php.gif");

if ($img) $img_height = imagesy($img);
if ($img) $img_width = imagesx($img);

// Create image instances
$dest = imagecreatefromgif('php.gif');
$src = imagecreatefromgif('php.gif');

// Copy and merge - Gray = 20%
imagecopymergegray($dest, $src, 0, 0, 0, 0, $img_width, $img_height, 20);

// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);

imagedestroy($dest);
imagedestroy($src);

?>

I remembered your question when I ways playing around with the PHP GD lib.

Good luck!! tell me if its any good...

Trufa

Trufa