Skip to content

Instantly share code, notes, and snippets.

@matori
Created April 5, 2016 12:11
Show Gist options
  • Save matori/b09d78969e9c8231c31373f88d23aa48 to your computer and use it in GitHub Desktop.
Save matori/b09d78969e9c8231c31373f88d23aa48 to your computer and use it in GitHub Desktop.
Convert colort to alpha
// http://paulownia.hatenablog.com/entry/20100420/1271769659
@function alphafy($front, $back, $alpha) {
$r: round((red($front) - red($back) * (1 - $alpha)) / $alpha);
$g: round((green($front) - green($back) * (1 - $alpha)) / $alpha);
$b: round((blue($front) - blue($back) * (1 - $alpha)) / $alpha);
@if($r < 0) {$r: 0;}
@if($r > 255) {$r: 255}
@if($g < 0) {$g: 0;}
@if($g > 255) {$g: 255}
@if($b < 0) {$b: 0;}
@if($b > 255) {$b: 255}
@return rgba($r, $g, $b, $alpha);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment