Forum Moderators: coopster
[php.net...]
there may be something in there that might be useful.
Method #1
function ConvertGreyscale($image){
# this file outputs a grey version of specified image
$total = ImageColorsTotal($image);
for( $i=0; $i<$total; $i++){
$old = ImageColorsForIndex($image, $i);
#trying to keep proper saturation when converting
$commongrey = (int)(($old[red] + $old[green] + $old[blue]) / 3);
ImageColorSet($image, $i, $commongrey, $commongrey, $commongrey);
}
}
Method #2
This little function does it for you:
<?
$image_id = imageCreateFromJPEG($image);
for($a=0;$a<imagecolorstotal ($image_id);$a++)
{
$color = ImageColorsForIndex($image_id,$i);
$R=.299 * ($color['red'])+ .587 * ($color['green'])+ .114 * ($color['blue']);
$G=.299 * ($color['red'])+ .587 * ($color['green'])+ .114 * ($color['blue']);
$B=.299 * ($color['red'])+ .587 * ($color['green'])+ .114 * ($color['blue']);
ImageColorSet($image_id, $a, $R, $G, $B);
}
imageJPEG($image_id,"$image");
?>
The .299 , .578 , .114 values are estimations, and add a gamma correction to the colors. For more or less luminace in the result, you can change these values.
Goodluck,
Eric Mulders, Netherlands
rossa at studioware dot net
23-Jan-2002 08:38