php获取图片颜色值的例子
时间:2021-07-01 10:21:17
帮助过:15人阅读
- /**
- * php获取图片颜色值
- * by bbs.it-home.org
- */
- $i=imagecreatefromjpeg("photo3.jpg");//测试图片,自己定义一个,注意路径
- for ($x=0;$x for ($y=0;$y $rgb = imagecolorat($i,$x,$y);
- $r=($rgb >>16) & 0xFF;
- $g=($rgb >> & 0xFF;
- $b=$rgb & 0xFF;
- $rTotal += $r;
- $gTotal += $g;
- $bTotal += $b;
- $total++;
- }
- }
- $rAverage = round($rTotal/$total);
- $gAverage = round($gTotal/$total);
- $bAverage = round($bTotal/$total);
- //示例:
- echo $rAverage;
- ?>
|