chroma.js icon indicating copy to clipboard operation
chroma.js copied to clipboard

rgba to rgb

Open GuySpotnix opened this issue 4 years ago • 2 comments

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!

GuySpotnix avatar May 10 '21 08:05 GuySpotnix

I'm disappointed no one has answered this question. I'm looking for the same information.

NotoriousWebmaster avatar Jul 12 '22 20:07 NotoriousWebmaster

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]);

jdanford avatar Feb 01 '23 19:02 jdanford