I would have needed this today. I wanted to tint a background image to be blue, so white text on top of the image is readable.
The current workaround is to make the image sepia first and apply hue rotation to make it (a very faint) blue. But that’s very unprecise because I’d need to know the hue value of the applied sepia color. Also, a saturate(9)
was needed to make the blue as vibrant as in the mockup. The endresult looks like this:
filter: contrast(0.2) sepia(1) hue-rotate(190deg) brightness(0.45) saturate(9);
IMO there should be a tint()
function that works similar to sepia()
with an absolute hue
or color
value as an additional parameter. Like:
filter: tint(blue, 0.7);
The second parameter is the “strength” of the effect, similar to how it works in sepia(0.7)
. That could become pretty handy.
I’ve tested the behavior of the tint feature in Affinity Designer. It has the following behavior. I don’t know if there’s a standard behavior but I’d agree if CSS worked the same way:
- Hue, saturation and brightness of the color passed to
tint(color, strength)
should affect the result
-
tint(white, 1)
and every color with a brightness of 100% would result in a completely white image
-
tint(black, 1)
and every color with a brightness of 0% would result in a completely black image
-
tint(gray, 1)
would remove all colors, similar to grayscale(1)
- I don’t know what exactly
sepia(1)
does but something similar should be achievable with tint(hsl(45, 40%, 50%), 1)
But what should happen with colors that include a non-1 alpha channel? Should it be ignored? I don’t think it’s a good idea to use the alpha channel as the filter strength to drop the need for a second argument. But I might be wrong.
IMO tint()
really should be a thing. What do you think?