PHP extracts the main color of any image

WBOY
Release: 2016-07-25 08:42:42
Original
1213 people have browsed it
  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


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template