Created:
Last modified:
SVG Filters - From a talk by Sara Souedian
I was watching an "An Event Apart" video SVG Filters: The Crash Course by Sara Soueidan, and I was so excited and intrigued to try out these SVG filters that I stopped the video part way through and decided I wanted to give the ones already shown a go. There is especially a part about creating dialated text to in essence create an outline to the text that doesn't eat into the width of the text.
Drop Shadow
First off Sara starts with the drop shadow, which, yes, in CSS is suuuuuuuper easy and basic to set up. But the SVG has some interesting aspects, even when just scratching the surface.
<svg class="svg-filter drop-shadow" width="600" height="450" viewBox="0 0 750 650">
<filter id="myFilter">
<feOffset in="SourceAlpha" dx="20" dy="20"></feOffset>
<feGaussianBlur stdDeviation="10" result="DROP"></feGaussianBlur>
<feColorMatrix type="matrix" in="DROPSHADOW" result="FINALSHADOW"
values="1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 0.3 0"></feColorMatrix>
<feMerge>
<feMergeNode in="FINALSHADOW"></feMergeNode>
<feMergeNode in="SourceGraphic"></feMergeNode>
</feMerge>
</filter>
<image xlink:href="..." x="0" y="0" width="100%" height="100%" filter="url(#myFilter)"></image>
</svg>
HTML:
<img class="img drop-shadow" src="..." width="600">
CSS:
filter: drop-shadow(20px 20px 10px hsla(0deg, 0%, 0%, 0.3));
Morphology Filter
Erode and Dilate are the two types of effects the feMorphology filter has. The Erode option 'crumbles' the
neighboroughing pixels at the edge of the item being filtered by the radius
value passed in, and Dilate option expands the filtered items pixels into it's neighboroughing pixels.
Apparently the erode filter sets the 'eroded' pixels to it darkest or most transparent neighbour and the dilate filter sets the dilated pixels to the brightest or least transparent pixel from it's neighbour. This is what makes an eroded image darker looking and a dilated image lighter looking.
It's text time
Hello World
Hello World
Hello World
p {
font-size: 8rem;
color: black;
font-weight: 700;
line-height: 1.2;
}
p.stroke {
-webkit-text-stroke: 3px deeppink;
}
p.shadow {
text-shadow: 3px 3px 3px deeppink, -3px -3px 3px deeppink,
-3px 3px 3px deeppink, 3px -3px 3px deeppink;
}
To change the colour of the outline, the 'flood-color' of the feFlood
property inside the SVG would have to be changed, so only controlled via the HTML itself or with a
Javascript call.
To change colour of the outline the 'stroke' property of text can be changed, meaning that it can be controlled via CSS, unlike the example prior.
"This is where the interesting stuff starts" - Sara
Like... really? I thought it was already plenty interesting. But Ok!
A write up on this is to come in the future...