blendColors
Composites a source color over a backdrop with a blend mode, as the browser does for
mix-blend-mode (W3C Compositing and Blending Level 1, source-over). Both colors are straight
(non-premultiplied); the maths run in premultiplied space.
Available since v3.1.8
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
backdrop | RgbColor | The color underneath |
source | RgbColor | The color painted over it |
mode | BlendMode | The blend mode. Defaults to `‘normal’`, a plain alpha composite. |
Returns
Section titled “Returns”RgbColor — The straight result: channels rounded to integers, alpha to 3 decimals
Examples
Section titled “Examples”Paint a half-transparent color over another
Section titled “Paint a half-transparent color over another”The default normal mode is a plain alpha composite.
Use a CSS blend mode
Section titled “Use a CSS blend mode”Same maths as mix-blend-mode, handy to compute what the browser would paint.
Related Types
Section titled “Related Types”RgbColor
Section titled “RgbColor”An RGB(A) color with channels expressed as plain numbers, convenient for further conversion or manipulation.
BlendMode
Section titled “BlendMode”The blend modes of the W3C Compositing and Blending specification, the same ones as CSS
mix-blend-mode. The last four (hue, saturation, color, luminosity) are non-separable:
they mix the three channels together instead of one channel at a time.
