I need to create a custom CSS filter that would convert black and white image to two-color image with two custom colors.
I want to apply filter in something like this way (not sure if this syntax is possible, maybe 6 arguments have to be passed separately):
.duotone {
-webkit-filter: custom(none url(/filters/duotone.fs),
black_color [255, 0, 0] white_color [255, 192, 203]);
}
so that black color is replaced with Red in this case, both the white and transparent colours (background) are replaced with Pink and all the shades of grey are replaced with colour in between (using straight-line curve).
Maybe it is even possible to define filter in CSS without an external file?
The application of this filter is to convert black/white icons to colored icons at run-time.
There are very few examples on how to do it, this one is very generic covering much wider range of filters and the specification is also not so easy to understand.
Could somebody post a working filter doing this or something similar? Or at least maybe you could point me to some more focused examples of application of ColorMatrix that will be relevant to my situation.
UPDATE:
In order to do that you will need to use -webkit-mask-image on CSS. This used to be a webkit only but it's now w3c css3.
The support is just present on webkit tho. In order to keep backward compatibility and display a regular black icon you will need to identify if the browser has this capabilities. I'v archived that using modernizr.
http://jsfiddle.net/kkobold/Zq5FZ/5/
old answer:
I believe thats the result you are looking for:
http://s7.postimage.org/vo5v33tuj/Screen_Shot_2013_02_03_at_11_28_46_PM.png
you can archive it by filtering to sepia and then changing hue degree. different combinations will give different results. But a simple color picker can be made for the hue and a slide for sepia to increase or decrease intensity of the color change.
and CSS3 only.
<div class="pull-left span4" > <img src="/img/bw.jpg" style="-webkit-filter: sepia(0.0) hue-rotate(0deg);" width="300"/><br /> -webkit-filter: sepia(0) hue-rotate(0deg); </div> <div class="pull-left span4" > <img src="/img/bw.jpg" style="-webkit-filter: sepia(0.8) hue-rotate(50deg);" width="300"/><br /> -webkit-filter: sepia(0.8) hue-rotate(50deg); </div> <div class="pull-left span4" > <img src="/img/bw.jpg" style="-webkit-filter: sepia(0.8) hue-rotate(100deg);" width="300"/><br /> -webkit-filter: sepia(0.8) hue-rotate(100deg); </div> <div class="pull-left span4" > <img src="/img/bw.jpg" style="-webkit-filter: sepia(0.8) hue-rotate(150deg);" width="300"/><br /> -webkit-filter: sepia(0.8) hue-rotate(150deg); </div> <div class="pull-left span4" > <img src="/img/bw.jpg" style="-webkit-filter: sepia(0.8) hue-rotate(200deg);" width="300"/><br /> -webkit-filter: sepia(0.8) hue-rotate(200deg); </div> <div class="pull-left span4" > <img src="/img/bw.jpg" style="-webkit-filter: sepia(0.8) hue-rotate(250deg);" width="300"/><br /> -webkit-filter: sepia(0.8) hue-rotate(250deg); </div> <div class="pull-left span4" > <img src="/img/bw.jpg" style="-webkit-filter: sepia(0.8) hue-rotate(300deg);" width="300"/><br /> -webkit-filter: sepia(0.8) hue-rotate(300deg); </div> <div class="pull-left span4" > <img src="/img/bw.jpg" style="-webkit-filter: sepia(0.8) hue-rotate(350deg);" width="300"/><br /> -webkit-filter: sepia(0.8) hue-rotate(350deg); </div>