Implementing CSS filters on the <img />
elements has been successful for me.
For example:
filter: brightness(1) contrast(67%) saturate(250%) grayscale(0%) invert(0%) hue-rotate(330deg) sepia(40%) blur(0px);
Now, I am trying to apply the same filter properties to the <image />
tag within an SVG file.
Unfortunately, methods like:
<g style="-webkit-filter: contrast(67%) saturate(250%);">
<image xlink:href="image.jpg" />
</g>
or
<image xlink:href="image.jpg" style="-webkit-filter: contrast(67%) saturate(250%) sepia(40%)"/>
are not yielding the desired results.
It seems that combining CSS filters as SVG filters might be necessary.
I discovered a representation of specific CSS filter effects on webplatform.org, such as:
invert:
Afterwards, I attempted to merge generated filters with feMerge
.
<filter id="clip_1-filter-90117969876336">
<feComponentTransfer in="SourceGraphic" result="brightness-filter">
<feFuncR type="linear" slope="22"></feFuncR>
<feFuncG type="linear" slope="22"></feFuncG>
<feFuncB type="linear" slope="22"></feFuncB>
</feComponentTransfer>
<feComponentTransfer in="brightness-filter" result="contrast-filter">
<feFuncR type="linear" slope="-15" intercept="7"></feFuncR>
<feFuncG type="linear" slope="-15" intercept="7"></feFuncG>
<feFuncB type="linear" slope="-15" intercept="7"></feFuncB>
</feComponentTransfer>
<feColorMatrix in="contrast-filter" result="grayscale-filter" type="matrix" values="
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0"></feColorMatrix>
<feComponentTransfer in="SourceGraphic" result="invert-filter">
<feFuncR type="table" tableValues="0 1"></feFuncR>
<feFuncG type="table" tableValues="0 1"></feFuncG>
<feFuncB type="table" tableValues="0 1"></feFuncB>
</feComponentTransfer>
<feMerge>
<feMergeNode in="grayscale-filter"></feMergeNode>
</feMerge>
</filter>
However, the outcomes are not meeting my expectations.
What is the correct approach for translating CSS filters to SVG?