当前位置 : 主页 > 网络编程 > PHP >

php提取图片的主要颜色

来源:互联网 收集:自由互联 发布时间:2021-07-03
$i = imagecreatefromjpeg("image.jpg");for ($x=0;$ximagesx($i);$x++) { for ($y=0;$yimagesy($i);$y++) { $rgb = imagecolorat($i,$x,$y); $r = ($rgb 16) 0xFF; $g = ($rgb 0xFF; $b = $rgb 0xFF; $rTotal += $r; $gTotal += $g; $bTotal += $b; $total++
$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);
网友评论