Created
December 24, 2024 11:34
-
-
Save glooer/422d5c6058e09f1d65f4680309be9ee7 to your computer and use it in GitHub Desktop.
RGB to RGBA over white
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://stackoverflow.com/a/6672545/13246729 | |
| convert_rgb_to_rgba = (r, g, b) => { | |
| const min = Math.min(r, g, b) | |
| const alpha = (255 - min) / 255 | |
| const result = { | |
| r: (r - min) / alpha, | |
| g: (g - min) / alpha, | |
| b: (b - min) / alpha, | |
| a: alpha | |
| } | |
| return `rgba(${~~result.r}, ${~~result.g}, ${~~result.b}, ${result.a.toFixed(2)})` | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment