Home  >  Article  >  Backend Development  >  php检测图片主要颜色的方法_php技巧

php检测图片主要颜色的方法_php技巧

WBOY
WBOYOriginal
2016-05-16 20:12:17956browse

本文实例讲述了php检测图片主要颜色的方法。分享给大家供大家参考。具体实现方法如下:

$i = imagecreatefromjpeg("image.jpg");
for ($x=0;$x<imagesx($i);$x++) {
  for ($y=0;$y<imagesy($i);$y++) {
    $rgb = imagecolorat($i,$x,$y);
    $r  = ($rgb >> 16) & 0xFF;
    $g  = ($rgb >> & 0xFF;
    $b  = $rgb & 0xFF;
    $rTotal += $r;
    $gTotal += $g;
    $bTotal += $b;
    $total++;
  }
}
$rAverage = round($rTotal/$total);
$gAverage = round($gTotal/$total);
$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