Joã*_*lva 3 css photoshop svg svg-filters
你能帮我找出如何使用 SVG 在下面的链接上实现棕褐色调吗?
我试过以下代码:
<svg class="defs-only">
<filter id="monochrome" color-interpolation-filters="sRGB"
x="0" y="0" height="100%" width="100%">
<feColorMatrix type="matrix"
values="1.00 0 0 0 0
0.80 0 0 0 0
0.65 0 0 0 0
0 0 0 1 0" />
</filter>
</svg>
Run Code Online (Sandbox Code Playgroud)
CSS:
img{
-webkit-filter: url(#monochrome);
filter: url(#monochrome);
}
Run Code Online (Sandbox Code Playgroud)
但是我得到的feColorMatrix Sepia Tone是非常不同的,而且似乎不像在 Photoshop 上那样只影响中间色调。
注意:我不能使用画布。
首先,这不是一个合适的棕褐色滤镜。它仅使用红色通道作为输入,因此您立即损失了大约三分之一的亮度。“官方”W3C 棕褐色过滤器是:
<feColorMatrix type="matrix"
values="0.39 0.769 0.189 0 0
0.349 0.686 0.168 0 0
0.272 0.534 0.131 0 0
0 0 0 1 0" />
Run Code Online (Sandbox Code Playgroud)
这给你这个结果:
如果您只想处理中间调,则需要将中间调拉出并单独处理。看起来像这样:
<filter id="mid-sepia" color-interpolation-filters="sRGB">
<feColorMatrix type="luminanceToAlpha"/>
<feComponentTransfer >
<feFuncA type="table" tableValues="0 .2 0.5 1 1 1 0.5 .2 0"/>
</feComponentTransfer>
<feComposite operator="in" in="SourceGraphic"/>
<feColorMatrix type="matrix" result="sepia-clip"
values="0.39 0.769 0.189 0 0
0.349 0.686 0.168 0 0
0.272 0.534 0.131 0 0
0 0 0 1 0" />
<feColorMatrix in="SourceGraphic" type="matrix" result="gscale"
values="0.2126 0.7152 0.0722 0 0
0.2126 0.7152 0.0722 0 0
0.2126 0.7152 0.0722 0 0
0 0 0 1 0" />
<feComposite operator="over" in="sepia-clip" in2="gscale"/>
</filter>
Run Code Online (Sandbox Code Playgroud)
并为您提供如下所示的内容:
这里的神奇之处在于 feFuncA 的设置——它控制着中间色调选择的宽度。“0 .2 0.5 1 1 1 0.5 .2 0”是一个相当广泛的选择——所以如果你想要一个更窄的棕褐色处理范围,你可能想要使用像“0 0 0 0.2 0.5 1 0.5 0.2 0 0 0”这样的东西“ - 玩它直到你有你喜欢的东西。
http://codepen.io/mullany/pen/rjdYre?editors=1000#