如果图片放到了七牛云,则通过七牛api可以直接获取图片平均色调(imageAve)
https://developer.qiniu.com/dora/api/1268/image-average-hue-imageave
这里获取的是图片的十六进制RGB
通过函数转换一下以下是PHP代码:
public function rgbToHsv($rgb)
{
//rgb十六进制转为十进制
$split = str_split($rgb, 2);
$r = hexdec($split[1]);
$g = hexdec($split[2]);
$b = hexdec($split[3]);
//十进制rgb转为hsv
$hsv_red = $r / 255;
$hsv_green = $g / 255;
$hsv_blue = $b / 255;
$hsv_max = max($hsv_red, $hsv_green, $hsv_blue);
$hsv_min = min($hsv_red, $hsv_green, $hsv_blue);
//v
$hsv_v = $hsv_max;
$hsv_d = $hsv_max - $hsv_min;
//s
$hsv_s = $hsv_max == 0 ? 0 : $hsv_d / $hsv_max;
//h
if ($hsv_max == $hsv_min) {
$hsv_h = 0;
} else {
switch ($hsv_max) {
case $hsv_red:
$hsv_h =

最低0.47元/天 解锁文章
326

被折叠的 条评论
为什么被折叠?



