Home  >  Article  >  Backend Development  >  PHP extracts the main color of any image

PHP extracts the main color of any image

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


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