Qix- / color-convert

Plain color conversion functions in JavaScript
MIT License
744 stars 96 forks source link

Failure to convert RGB to HSL and back #85

Closed marnec closed 4 years ago

marnec commented 4 years ago

input:

console.log(r, g, b);
console.log(convert.rgb.hsl(...convert.hsl.rgb(r,g,b)))

output:

0 51 255
[180, -51, 255]
Qix- commented 4 years ago

Because you're passing RGB values to hsl.rgb() which means convert hsl to rgb - the functions are structured so that require('color-convert').from_model.to_model(...).

You need to invert the function calls:

console.log(convert.hsl.rgb(...convert.rgb.hsl(r,g,b)))