Here's an online CSS generator to convert to a target color.
For example, if you enter #CC0000
it will give you:
filter: invert(8%) sepia(97%) saturate(7488%) hue-rotate(12deg) brightness(92%) contrast(114%);
It will also score the result for accuracy. You can keep trying until you get a perfect score.
I believe it assumes your image is black. If its not, to turn the image black first prepend this:
brightness(0) saturate(100%)
So using the earlier example the final solution (if your image is not black) would be:
filter: brightness(0) saturate(100%) invert(8%) sepia(97%) saturate(7488%) hue-rotate(12deg) brightness(92%) contrast(114%);
Now if only someone would write an npm package to do this for you dynamically!
sepia(100%)
was great to get a white image to have color by reducingbrightness(0.9)
and then applying sepia, the there is a hue for rotating. – Catchings