Calculate colour temperature in K

前端 未结 6 1018
忘掉有多难
忘掉有多难 2021-01-07 19:55

I have written a lib for working with colours and stuck trying to calculate Tc(k). From what I have read working in the CIE 1931 XYZ colour space i

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-07 20:01

    Found the Temperature to RGB solution written in JavaScript and converted it into PHP.

     clamp($red,   0, 255),
            'g' => clamp($green, 0, 255),
            'b' => clamp($blue,  0, 255)
        ];
    }
    
    function clamp($x, $min, $max)
    {
        if ($x < $min)
            return $min;
    
        if ($x > $max)
            return $max;
    
        return $x;
    }
    
    var_dump(colorTemperatureToRGB(7000));
    

提交回复
热议问题