经测试代码如下:
/**
* 检测图片主要颜色
*
* @param
* @author 编程之家 jb51.cc jb51.cc
**/
$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);
/*** 代码来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/529027.html