改变#RGB颜色的饱和度:这里有什么遗漏? [英] Altering Saturation of #RGB Color: Whats Missing Here?

查看:172
本文介绍了改变#RGB颜色的饱和度:这里有什么遗漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个亮度/饱和度替代程序的概念,其中亮度()和饱和度() / p>

 函数亮度($ colorstr,$ steps){
...
返回sprintf(%02x %02x%02x,$ r,$ g,$ b);
}
函数饱和(){
...
返回sprintf(%02x%02x%02x,$ r,$ g,$ b);





$ b

是否有任何现有的简单易用的在线时尚来补充这一点使得以下可能:

  $ color2 =饱和度($ color,-10); / *较少staurated * / 
$ color3 =饱和度($ color,+ 10); / *更加稳定* /


解决方案

饱和度和亮度不能处理相同(可以争辩说,你没有正确处理使用此代码的亮度,但它可能足够接近)。看到这个问题 RGB到HSV in PHP for如何将颜色转换为HSV值,然后您可以修改饱和度(S值)。然后使用这个问题的答案转换回来 PHP HSV到RGB 。 p>

Below is a concept for a brightness/saturation alterarion programm with brightness() and saturation().

function brightness($colorstr, $steps) { 
    ...
    return sprintf("%02x%02x%02x", $r, $g, $b);
} 
function saturation(){ 
    ...
    return sprintf("%02x%02x%02x", $r, $g, $b);
}

Are there any existing simple to use fashions online to complement this ane make the following possible:

$color2 = saturation($color,-10); /* less staurated*/
$color3 = saturation($color,+10); /* more staurated*/

解决方案

Saturation and brightness cannot be handled the same (one could argue that your aren't handling brightness correctly using this code but it's probably close enough). See this question RGB to HSV in PHP for how to convert the color to an HSV value then you can modify the saturation (the S value). Then convert back using the answer to this question PHP HSV to RGB.

这篇关于改变#RGB颜色的饱和度:这里有什么遗漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆