1 <?php 2 /** 3 * Date: 2016/10/24 4 * Time: 0:52 5 */ 6 // Gray = (R^2.2 * 0.2973 + G^2.2 * 0.6274 + B^2.2 * 0.0753)^(1/2.2) 7 $size = getimagesize('png.png'); 8 $res = imagecreatefrompng('png.png'); 9 for ($i = 0; $i < $size[1]; ++$i) { 10 for ($j = 0; $j < $size[0]; ++$j) { 11 $rgb = imagecolorat($res, $j, $i); 12 // var_dump($rgb); 13 $rgbarray = imagecolorsforindex($res, $rgb); 14 print_r($rgbarray); 15 $wr = $rgbarray['red']; 16 $wg = $rgbarray['green']; 17 $wb = $rgbarray['blue']; 18 $gray = ($wr ^ 2.2 * 0.2973 + $wg ^ 2.2 * 0.6274 + $wb ^ 2.2 * 0.0753) ^ (1 / 2.2); 19 echo $gray, '<br>'; 20 21 //??? 22 if ($rgbarray['red'] < 125 || $rgbarray['green'] < 125 || 23 $rgbarray['blue'] < 125 24 ) { 25 $data[$i][$j] = 1; 26 } else { 27 $data[$i][$j] = 0; 28 } 29 30 } 31 }