umm ds la doc, ya des exemples pr passer en nivo de gris ...
theviruskiller at hotmail dot com
07-Aug-2001 08:44
Does anybody know a function to convert a 32bit JPEG image to greyscale? I've tried to do it myself by calculating the luminence value of each color and connecting that value to a grey value, but this doesn't work properly. Any suggestions??
eric at spiderws dot com
12-Aug-2001 11:45
This little function does it for you:
Code :
- <?
- $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
Code :
- 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);
- }
- }
|
http://www.php.net/manual/fr/funct [...] ecolor.php