2.0.0 • Published 3 months ago

@napolab/alpha-blend v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

@napolab/alpha-blend

@napolab/alpha-blend library image

A TypeScript package to perform the alpha blending of two colors based on the given mathematical formulas.

Formulas

The blending is calculated using the following formulas:

\begin{align}
\alpha &= \alpha_b \alpha_f + \alpha_b (1 - \alpha_f) + (1 - \alpha_b) \alpha_f \tag{1} \\
&= \alpha_b + \alpha_f - \alpha_b \alpha_f \\
&= \alpha_b (1 - \alpha_f) + \alpha_f \\
C &= \frac{\alpha_b (1 - \alpha_f) C_b + \alpha_f C_f}{\alpha} \tag{4}
\end{align}

For a detailed explanation, please refer to this article.

Usage

Features

  • Blend two colors with their respective alpha values.
  • Get the resulting color in HEX format.
  • Handle both HEX and RGBA input formats.

Sample Code

import { alphaBlend } from "@napolab/alpha-blend";

const foregroundColor = "#ff5733";
const backgroundColor = "rgba(255, 87, 51, 0.5)";
const blendedColor = alphaBlend(foregroundColor, backgroundColor);

// Outputs: '#ff5733ff'.
blendedColor;

Installation

To install the package, use:

npm install @napolab/alpha-blend

or

yarn add @napolab/alpha-blend

License

This project is licensed under the MIT License.

2.0.0

3 months ago

1.0.3

8 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago