Closed GuySpotnix closed 2 weeks ago
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]);
Another easy way to get a non-transparent color that looks the same as if the color would be transparent against a background is to use chroma.mix
. Here's a quick example for getting the equivalent color of red with 70% opacity against a white background:
const equivalentColor = chroma.mix('white', 'red', 0.7, 'rgb');
Here's an Observable notebook demonstrating this: https://observablehq.com/@gka/chroma-remove-alpha-from-color
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!