Home  >  Article  >  Backend Development  >  php extract main color of image

php extract main color of image

WBOY
WBOYOriginal
2016-07-25 08:45:171059browse
  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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn