4) $out[] = $color[4]; // copy alpha return $out; } protected static function toRGBHelper($comp, $temp1, $temp2) { if ($comp < 0) $comp += 1.0; elseif ($comp > 1) $comp -= 1.0; if (6 * $comp < 1) return $temp1 + ($temp2 - $temp1) * 6 * $comp; if (2 * $comp < 1) return $temp2; if (3 * $comp < 2) return $temp1 + ($temp2 - $temp1) * ((2 / 3) - $comp) * 6; return $temp1; } protected static function toRGB($color) { if ($color == 'color') return $color; $H = $color[1] / 360; $S = $color[2] / 100; $L = $color[3] / 100; if ($S == 0) { $r = $g = $b = $L; } else { $temp2 = $L < 0.5 ? $L * (1.0 + $S) : $L + $S - $L * $S; $temp1 = 2.0 * $L - $temp2; $r = self::toRGBHelper($H + 1 / 3, $temp1, $temp2); $g = self::toRGBHelper($H, $temp1, $temp2); $b = self::toRGBHelper($H - 1 / 3, $temp1, $temp2); } $out = array('color', round($r * 255), round($g * 255), round($b * 255)); if (count($color) > 4) $out[] = $color[4]; // copy alpha return $out; } protected static function clamp($v, $max = 1, $min = 0) { return min($max, max($min, $v)); } }