[PHP] 取得主要色值 RGB
function imgColor($imgUrl) {
$imageInfo = getimagesize($imgUrl);
$imgType = strtolower(substr(image_type_to_extension($imageInfo[2]), 1));
$imageFun = 'imagecreatefrom' . ($imgType == 'jpg' ? 'jpeg' : $imgType);
$i = $imageFun($imgUrl);
$rColorNum=$gColorNum=$bColorNum=$total=0;
for ($x=0;$x
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$rColorNum += $r;
$gColorNum += $g;
$bColorNum += $b;
$total++;
}
}
$rgb = array();
$rgb['r'] = round($rColorNum/$total);
$rgb['g'] = round($gColorNum/$total);
$rgb['b'] = round($bColorNum/$total);
return $rgb;
}
留言