function imagegreyscale(&$img, $dither=1) {
if (!($t = imagecolorstotal($img))) {
$t = 256;
imagetruecolortopalette($img, $dither, $t);
}
for ($c = 0; $c < $t; $c++) {
$col = imagecolorsforindex($img, $c);
$min = min($col['red'],$col['green'],$col['blue']);
$max = max($col['red'],$col['green'],$col['blue']);
$i = ($max+$min)/2;
imagecolorset($img, $c, $i, $i, $i);
}
}

function imagecolorgrey( &$img ) {
for( $i=0; $i<imagecolorstotal( $img ); $i++ ) {
$c = ImageColorsForIndex( $img, $i );
$t = ($c["red"]+$c["green"]+$c["blue"])/3;
imagecolorset( $img, $i, $t, $t, $t );
}
}

QUESTE NON MI FUNZIONANO... why!!!!???