当前位置:Gxlcms > PHP教程 > PHP提取任意图片的主颜色

PHP提取任意图片的主颜色

时间:2021-07-01 10:21:17 帮助过:11人阅读

  1. function dominant_color($image)
  2. {
  3. $i = imagecreatefromjpeg($image);
  4. for ($x=0;$x for ($y=0;$y $rgb = imagecolorat($i,$x,$y);
  5. $r = ($rgb >> 16) & 0xFF;
  6. $g = ($rgb >> & 0xFF;
  7. $b = $rgb & 0xFF;
  8. $rTotal += $r;
  9. $gTotal += $g;
  10. $bTotal += $b;
  11. $total++;
  12. }
  13. }
  14. $rAverage = round($rTotal/$total);
  15. $gAverage = round($gTotal/$total);
  16. $bAverage = round($bTotal/$total);
  17. }

PHP

人气教程排行