toColor
Using
Convert a color of one type to another.
Demo - use JSON
toColor( , , )
"cmyk(0%, 79%, 95%, 5%)"
Arguments
Argument | Type | Description | Possible Values | Example |
---|---|---|---|---|
color | number[] object string | Any color in any format. | [15, 76, 213] {r: 255, g: 14, b: 148 } "cmyk(63, 69, 5.5, 34)" "#F33333" {h: 200, s: 50, v: 45} | |
to | string | Return type. | "object" "rgb-object" "rgb-array" "rgb-string" "cmyk-object" "cmyk-array" "cmyk-string" "hex-string" "hsv-object" "hsv-array" "hsv-string" | "hsv-array" |
fromColorType | string | The color from which we will get the result. Can help when the source value is not defined. | "rgb" "cmyk" "hex" "hsv" | "cmyk" |
Returns
number[]
| object
| string
— Returns the color in one of the formats.
Examples
Quick view
toColor([93, 255, 101], 'rgb-object');
// { r: 93, g: 255, b: 101 }
toColor({ c: 64, m: 21, y: 99, k: 2 }, 'rgb-array');
// [90, 197, 2]
toColor({ r: 9.8, g: 32, b: 11 }, 'rgb-string');
// rgb(9, 32, 11)
toColor('rgb(190,88,17)', 'cmyk-string');
// 'cmyk(0%, 54%, 91%, 25%)'
toColor({ c: 242, m: 52, y: 11, k: 10 }, 'hsv-object');
// { h: 208, s: 100, v: 80 }