http://www.electronika.fr/blog/?p=118###################### //################################################################################## function trans_to_nb($file,$file_out){ if (file_exists($file)){ $image = imagecreatefromjpeg($file); $x_dimension = imagesx($image); $y_dimension = imagesy($image); $new_image = imagecreatetruecolor($x_dimension, $y_dimension);// for ($x = 0; $x < $x_dimension; $x++) { for ($y = 0; $y < $y_dimension; $y++) { $luminance_running_sum=0; $rgb = imagecolorat($image, $x, $y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $luminance_running_sum = (0.30 * $r) + (0.59 * $g) + (0.11 * $b); $color = imagecolorallocate($image, $luminance_running_sum, $luminance_running_sum, $luminance_running_sum ); imagesetpixel($new_image, $x, $y, $color); } } imagejpeg($new_image, $file_out); return true; }else{ return false; } } if (trans_to_nb("test.jpg","out.jpg")){ echo""; } else { echo"erreur fichier source inexistant"; } ?>