Example of getting the color value of an image in php

WBOY
Release: 2016-07-25 08:53:06
Original
1215 people have browsed it
  1. /**
  2. * php gets the color value of the image
  3. * by bbs.it-home.org
  4. */
  5. $i=imagecreatefromjpeg("photo3.jpg");//Test image, define one yourself, pay attention to the path
  6. for ($x=0; $x for ($y=0;$y $rgb = imagecolorat($i,$x,$y);
  7. $r=($rgb >>16) & 0xFF;
  8. $g=($rgb >> & 0xFF;
  9. $b=$rgb & 0xFF;
  10. $rTotal += $r;
  11. $gTotal += $g;
  12. $bTotal += $b;
  13. $total++;
  14. }
  15. }
  16. $rAverage = round($rTotal/$total);
  17. $gAverage = round($gTotal/$total);
  18. $bAverage = round($bTotal/$total);
  19. //Example:
  20. echo $rAverage;
  21. ?>
Copy code


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!