PHP HSV 到 RGB 公式理解
我可以使用以下代码将 RGB 值转换为 HSV...
$r = $r/255;
$g = $g/255;
$b = $b/255;
$h = 0;
$s = 0;
$v = 0;
$min = min(min($r, $g),$b);
$max = max(max($r, $g),$b);
$r = $max-$min;
$v = $max;
if($r == 0){
$h = 0;
$s = 0;
}
else {
$s = $r / $max;
$hr = ((($max - $r) / 6) + ($r / 2)) / $r;
$hg = ((($max - $g) / 6) + ($r / 2)) / $r;
$hb = ((($max - $b) / 6) + ($r / 2)) / $r;
if ($r == $max) $h = $hb - $hg;
else if($g == $max) $h = (1/3) + $hr - $hb;
else if ($b == $max) $h = (2/3) + $hg - $hr;
if ($h < 0)$h += 1;
if ($h > 1)$h -= 1;
}
但是如何将 HSV 转换为 < PHP 中的strong>RGB???
以下是维基百科上的内容,但我不明白,
我猜它很明显
I can convert RGB values to HSV with the following code...
$r = $r/255;
$g = $g/255;
$b = $b/255;
$h = 0;
$s = 0;
$v = 0;
$min = min(min($r, $g),$b);
$max = max(max($r, $g),$b);
$r = $max-$min;
$v = $max;
if($r == 0){
$h = 0;
$s = 0;
}
else {
$s = $r / $max;
$hr = ((($max - $r) / 6) + ($r / 2)) / $r;
$hg = ((($max - $g) / 6) + ($r / 2)) / $r;
$hb = ((($max - $b) / 6) + ($r / 2)) / $r;
if ($r == $max) $h = $hb - $hg;
else if($g == $max) $h = (1/3) + $hr - $hb;
else if ($b == $max) $h = (2/3) + $hg - $hr;
if ($h < 0)$h += 1;
if ($h > 1)$h -= 1;
}
But how do you convert HSV to RGB in PHP???
The following is on wikipedia but I don't understand it,
I'm guessing it's pretty obvious
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这适用于
[0,1]
范围内的 HSV 值(并给出[0,1]
范围内的 RGB 值,而不是{0 , 1, ..., 255}
:This is for the the HSV values in the range
[0,1]
(and giving RGB values in the range[0,1]
, instead of{0, 1, ..., 255}
:将 HSL 的滚动答案从 C 翻译为 PHP
Translation of rolls answer for HSL from C to PHP
发现这篇文章太晚了,我的替代方案:
hsv2rgb function PHP
hue: 0-360, sat: 0-100, val: 0-100
Found this post too late, my alternate take on it:
hsv2rgb function PHP
hue: 0-360, sat: 0-100, val: 0-100
ColorJizz 允许您在多种格式之间进行转换。还有一个 PHP 版本。
ColorJizz allows you to convert from/to many formats. There is a PHP version too.