Skip to content

Instantly share code, notes, and snippets.

@jdudek
Created September 16, 2016 09:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jdudek/54c80e27510b9b13d4447f803869118f to your computer and use it in GitHub Desktop.
Save jdudek/54c80e27510b9b13d4447f803869118f to your computer and use it in GitHub Desktop.
@function blend-transparent($foreground, $background) {
// https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
$fg-opacity: opacity($foreground);
$bg-opacity: opacity($background);
$opacity: $fg-opacity + $bg-opacity * (1.0 - $fg-opacity);
$factor: $bg-opacity * (1.0 - $fg-opacity);
$red: (red($foreground) * $fg-opacity + red($background) * $factor) / $opacity;
$green: (green($foreground) * $fg-opacity + green($background) * $factor) / $opacity;
$blue: (blue($foreground) * $fg-opacity + blue($background) * $factor) / $opacity;
@return rgba($red, $green, $blue, $opacity);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment