Created
January 24, 2023 14:54
-
-
Save cedeber/71f1ba3e683c113aeda170ea193e900a to your computer and use it in GitHub Desktop.
Recolor an image-based icon by applying a SVG filter
This file contains 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
@mixin recolor($color: #000, $opacity: 1) { | |
$r: red($color) / 255; | |
$g: green($color) / 255; | |
$b: blue($color) / 255; | |
$a: $opacity; | |
// grayscale fallback if SVG from data url is not supported | |
$lightness: lightness($color); | |
filter: saturate(0%) brightness(0%) invert($lightness) opacity($opacity); | |
// color filter | |
$svg-filter-id: "recolor"; | |
filter: url('data:image/svg+xml;utf8,\ | |
<svg xmlns="http://www.w3.org/2000/svg">\ | |
<filter id="#{$svg-filter-id}" color-interpolation-filters="sRGB">\ | |
<feColorMatrix type="matrix" values="\ | |
0 0 0 0 #{$r}\ | |
0 0 0 0 #{$g}\ | |
0 0 0 0 #{$b}\ | |
0 0 0 #{$a} 0\ | |
"/>\ | |
</filter>\ | |
</svg>\ | |
##{$svg-filter-id}'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment