Qix- / color-convert

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

Convertation is differrent #101

Closed mcfly10 closed 2 years ago

mcfly10 commented 2 years ago

Hi,

I getting different values converting from RGB to HSL and then back

var convert = require('color-convert');

console.log("A38E8E", " => ", convert.hex.hsl("A38E8E")); // Result A38E8E
console.log([0, 10, 60], " => ", convert.hsl.hex(0, 10, 60)); // Result A38F8F. Expected A38E8E

Converting A38E8E I get [0, 10, 60] Converting [0, 10, 60] I get A38F8F. Not A38E8E!

Qix- commented 2 years ago

https://github.com/Qix-/color-convert#api

Please read about rounding. Use .raw() if you need to preserve accuracy. Also, keep in mind hex will always truncate, which means you're losing data. Conversion between HSL and RGB is not perfect.

> console.log(convert.hsl.hex(convert.hex.hsl('A38E8E')))
A38F8F

> console.log(convert.hsl.hex(convert.hex.hsl.raw('A38E8E')))
A38E8E