16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xF">
当前位置:Gxlcms > PHP教程 > php提取图片的主要颜色

php提取图片的主要颜色

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

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

php

人气教程排行