chroma.js
chroma.js copied to clipboard
rgba to rgb
Hi every one,
I'm looking for a way to get rgb out of rgba color (with white as back color). Not sure how to do that using chroma js.
Ref: https://stackoverflow.com/questions/2049230/convert-rgba-color-to-rgb
Thanks!
I'm disappointed no one has answered this question. I'm looking for the same information.
There isn't a built-in solution, but you can do it with weighted averaging:
const color = chroma("rgba(255, 0, 0, 0.5)");
const alpha = color.alpha();
const colorWithFullAlpha = color.alpha(1);
chroma.average([colorWithFullAlpha, "white"], "rgb", [alpha, 1 - alpha]);