Is it possible to transform a font with CSS to have rounded edges?
I'm talking about an effect similar to this smooth edges in Photoshop
So far I tried using a SVG filter, but it seems a bit complicated.
Is there a better way?
The code for the SVG filter used is this:
<svg viewbox="0 0 100% 100%">
<defs>
<filter id="smooth">
<feMorphology operator="dilate" radius="0" />
<feGaussianBlur stdDeviation="3" />
<feComponentTransfer>
<feFuncA type="table" tableValues="0 0 1 1"></feFuncA>
</feComponentTransfer>
<feComponentTransfer>
<feFuncA type="table" tableValues="0 0 1 1"></feFuncA>
</feComponentTransfer>
<feComponentTransfer out="rounded1">
<feFuncA type="table" tableValues="0 0 1 1"></feFuncA>
</feComponentTransfer>
<feComposite in2="rounded1" in="SourceGraphics" operator="in"/>
</filter>
</defs>
</svg>
and the explanations are here: https://dev.to/codingdudecom/css-smooth-font-edges-3pbb
One possible solution is using a goo filter like so. As an observation you need to know that for a different font and a different font-size you may need to change the values of the feColorMatrix and stdDeviation
div {
height: 200px;
padding:10px 60px;
font-size:200px;
font-family:Arial;
filter:url(#goo);
}
svg{position:absolute;}
<svg width="0" height="0">
<defs>
<filter id="goo">
<feGaussianBlur in="SourceGraphic" stdDeviation="7" />
<feColorMatrix mode="matrix" values="1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 35 -7" />
<feBlend in="SourceGraphic" />
</filter>
</defs>
</svg>
<div>
<span>A B</span>
</div>
Please read about The Goeey Effect
Related
I'm trying to add some inset shadows to my svg, to make it look more like this
Instead of like this
I tried adding an inset shadow to every path (filter="url(#inset-shadow)"), using the filter pattern I got from this answer and have listed below, but all it ends up doing is kind of giving each path an outline. You can check the code at this fiddle to see what I'm talking about.
<filter id="inset-shadow">
<feComponentTransfer in="SourceAlpha" result="inset-selection">
<feFuncA type="discrete" tableValues="0 1 1 1 1 1" />
</feComponentTransfer>
<feComponentTransfer in="SourceGraphic" result="original-no-fill">
<feFuncA type="discrete" tableValues="0 0 1" />
</feComponentTransfer>
<feColorMatrix type="matrix" in="original-no-fill" result="new-source-alpha" values="0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 1 0" />
<feGaussianBlur in="new-source-alpha" result="blur" stdDeviation="5" />
<feGaussianBlur in="new-source-alpha" result="blur2" stdDeviation="10" />
<feGaussianBlur in="new-source-alpha" result="blur3" stdDeviation="15" />
<feMerge result="blur">
<feMergeNode in="blur" mode="normal" />
<feMergeNode in="blur2" mode="normal" />
<feMergeNode in="blur3" mode="normal" />
</feMerge>
<feComposite operator="in" in="inset-selection" in2="blur" result="inset-blur" />
<feComposite operator="over" in="original-no-fill" in2="inset-blur" />
</filter>
How can I add inset shadows to my shapes, to make my svg look more like the image at the top of this post?
The one you are using may have been failing because it was intended for transparent paths. I didn't spend much time working out what is wrong.
In any case, here's one I've created, that might be a bit easier to understand and tinker with.
<svg viewBox="0 0 200 200" width="400">
<defs>
<filter id="inset-shadow" x="-50%" y="-50%" width="200%" height="200%">
<!-- change this to desired inset blur colour -->
<feFlood x="0%" y="0%" width="100%" height="100%" flood-color="black" result="flood"/>
<!-- cut a hole out of the flood fill where out shape is -->
<feComposite operator="out" in="flood" in2="SourceAlpha" result="outside" />
<!-- stack blurs to get a better effect -->
<feGaussianBlur in="outside" result="blur" stdDeviation="5" />
<feGaussianBlur in="outside" result="blur2" stdDeviation="10" />
<feGaussianBlur in="outside" result="blur3" stdDeviation="15" />
<feMerge result="blur">
<feMergeNode in="blur" mode="normal" />
<feMergeNode in="blur2" mode="normal" />
<feMergeNode in="blur3" mode="normal" />
</feMerge>
<!-- clip the full blur against the shape to retain just the part inside our shape -->
<feComposite operator="in" in="blur" in2="SourceGraphic" result="inset-blur" />
<!-- blend with our original graphic to create the final result -->
<feBlend in="SourceGraphic" in2="inset-blur" mode="multiply"/>
</filter>
</defs>
<rect x="50" y="50" width="100" height="100" fill="linen" filter="url(#inset-shadow)"/>
</svg>
And here is a modified version of your fiddle with this filter applied.
You may want to tinker with the stdDeviation values to adjust the size of your inset blur.
So I am having issues with svg and all of its quirks, where I cannot <use> an <svg> from a file where I store all of my <svg> designs.
I tried using various methods to display the <svg> using <object> <img> & <svg> <use>, but no success.
The svg just does not display on the browser when I have an svg inside a <symbol> that contains other attributes like <g> Or <defs>,
however <symbol> svg's that contain just <path> work perfectly fine.
Project Structure:
assets/
|-> svg-icons.svg (<-- Main SVG icons location)
|-> checkMark.svg (<-- Copy of <symbol id="checkMark" in svg-icons.svg)
index.html
svg-icons.svg
<svg xmlns="http://www.w3.org/2000/svg">
<!--
Checkmark vector icon
-->
<symbol id="checkMark" width="27" height="27" viewBox="0 0 27 27" fill="black">
<g filter="url(#filter0_d)">
<path
d="M13.6635 6.5408C9.67777 6.5408 6.43506 9.78351 6.43506 13.7692C6.43506 17.7549 9.67777 20.9977 13.6635 20.9977C17.6492 20.9977 20.8919 17.7549 20.8919 13.7692C20.8919 9.78351 17.6492 6.5408 13.6635 6.5408ZM17.4254 11.3467L12.7547 16.907C12.7035 16.968 12.6397 17.0173 12.5678 17.0515C12.4958 17.0858 12.4174 17.1042 12.3377 17.1054H12.3283C12.2504 17.1054 12.1733 17.089 12.1021 17.0573C12.0309 17.0255 11.9672 16.9792 11.9151 16.9212L9.91339 14.6971C9.86255 14.6432 9.82301 14.5796 9.79708 14.5102C9.77115 14.4408 9.75936 14.3669 9.76239 14.2929C9.76543 14.2188 9.78324 14.1461 9.81478 14.0791C9.84631 14.012 9.89093 13.9519 9.94601 13.9024C10.0011 13.8528 10.0655 13.8147 10.1355 13.7904C10.2055 13.7661 10.2797 13.756 10.3537 13.7608C10.4276 13.7655 10.4999 13.785 10.5662 13.8181C10.6325 13.8512 10.6915 13.8972 10.7398 13.9534L12.3137 15.7021L16.574 10.6315C16.6695 10.521 16.8047 10.4525 16.9503 10.4409C17.096 10.4293 17.2403 10.4755 17.3521 10.5695C17.464 10.6634 17.5344 10.7976 17.5481 10.943C17.5618 11.0885 17.5177 11.2335 17.4254 11.3467V11.3467Z"
fill="#333333" />
</g>
<defs>
<filter id="filter0_d" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" />
<feOffset />
<feGaussianBlur stdDeviation="2.78016" />
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" />
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow" />
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape" />
</filter>
</defs>
</symbol>
<!-- House on sale/rent vector icon -->
<symbol id='sell-house-vector' width="44" height="52" viewBox="0 0 44 52">
<path
d="M10.6449 38.3145C10.6449 39.419 11.5403 40.3145 12.6449 40.3145H40.5794C41.684 40.3145 42.5794 39.419 42.5794 38.3145V14.9915C42.5794 13.887 41.684 12.9915 40.5794 12.9915H12.6449C11.5403 12.9915 10.6449 13.887 10.6449 14.9915V38.3145ZM25.5578 16.8353C26.3121 16.1898 27.4259 16.1954 28.1737 16.8485L36.796 24.3786C37.3467 24.8596 37.0065 25.7662 36.2754 25.7662C35.8382 25.7662 35.4839 26.1205 35.4839 26.5576V35.8306C35.4839 36.9351 34.5885 37.8306 33.4839 37.8306H30.7414C29.6369 37.8306 28.7414 36.9351 28.7414 35.8306V31.3145C28.7414 30.2099 27.846 29.3145 26.7414 29.3145H26.4829C25.3783 29.3145 24.4829 30.2099 24.4829 31.3145V35.8306C24.4829 36.9351 23.5874 37.8306 22.4829 37.8306H20.0966C18.992 37.8306 18.0966 36.9351 18.0966 35.8306V26.5689C18.0966 26.1256 17.7372 25.7662 17.2939 25.7662C16.5484 25.7662 16.2056 24.8384 16.772 24.3536L25.5578 16.8353ZM9.09657 6.2501C7.992 6.2501 7.09657 5.35467 7.09657 4.2501V2C7.09657 0.895432 6.20114 0 5.09657 0H2C0.89543 0 0 0.895431 0 2V49.3145C0 50.419 0.89543 51.3145 2 51.3145H5.09657C6.20114 51.3145 7.09657 50.419 7.09657 49.3145V11.4443C7.09657 10.3397 7.992 9.44429 9.09657 9.44429H42.4029C43.285 9.44429 44 8.72924 44 7.84719C44 6.96514 43.285 6.2501 42.4029 6.2501H9.09657Z" />
</symbol>
<!-- Search Property vector icon -->
<symbol id='search-vector' width="35" height="34" viewBox="0 0 35 34">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M25.7641 23.2125C28.0071 20.3208 29.0643 16.6831 28.7204 13.0396C28.3765 9.39611 26.6575 6.02045 23.9131 3.59938C21.1687 1.17831 17.605 -0.1063 13.9471 0.00689208C10.2891 0.120084 6.81171 1.62258 4.22224 4.2087C1.63051 6.79661 0.12311 10.2754 0.00721327 13.9361C-0.108684 17.5968 1.17565 21.164 3.59848 23.9107C6.02132 26.6574 9.40031 28.3768 13.0469 28.7187C16.6935 29.0606 20.3332 27.9991 23.2243 25.7506L23.3016 25.8315L30.932 33.4637C31.0991 33.6308 31.2975 33.7633 31.5158 33.8538C31.7342 33.9442 31.9682 33.9908 32.2046 33.9908C32.4409 33.9908 32.675 33.9442 32.8933 33.8538C33.1117 33.7633 33.3101 33.6308 33.4772 33.4637C33.6443 33.2965 33.7769 33.0981 33.8673 32.8798C33.9578 32.6614 34.0043 32.4274 34.0043 32.191C34.0043 31.9547 33.9578 31.7207 33.8673 31.5023C33.7769 31.2839 33.6443 31.0855 33.4772 30.9184L25.8451 23.2881C25.8188 23.2622 25.7918 23.237 25.7641 23.2125ZM22.0299 6.75394C23.0455 7.75311 23.8532 8.94347 24.4064 10.2564C24.9597 11.5692 25.2475 12.9787 25.2533 14.4034C25.2591 15.828 24.9828 17.2398 24.4402 18.5571C23.8977 19.8745 23.0997 21.0714 22.0923 22.0788C21.0849 23.0862 19.888 23.8842 18.5707 24.4267C17.2533 24.9692 15.8416 25.2455 14.4169 25.2397C12.9922 25.2339 11.5828 24.9461 10.2699 24.3929C8.95701 23.8397 7.76665 23.032 6.76748 22.0164C4.77071 19.9868 3.65681 17.2505 3.6684 14.4034C3.68 11.5563 4.81615 8.82906 6.82937 6.81583C8.8426 4.80261 11.5698 3.66646 14.4169 3.65486C17.264 3.64327 20.0004 4.75717 22.0299 6.75394Z" />
</symbol>
</svg>
checkMark.svg
<svg xmlns="http://www.w3.org/2000/svg" id="checkMark" width="27" height="27" viewBox="0 0 27 27" fill="black">
<g filter="url(#filter0_d)">
<path
d="M13.6635 6.5408C9.67777 6.5408 6.43506 9.78351 6.43506 13.7692C6.43506 17.7549 9.67777 20.9977 13.6635 20.9977C17.6492 20.9977 20.8919 17.7549 20.8919 13.7692C20.8919 9.78351 17.6492 6.5408 13.6635 6.5408ZM17.4254 11.3467L12.7547 16.907C12.7035 16.968 12.6397 17.0173 12.5678 17.0515C12.4958 17.0858 12.4174 17.1042 12.3377 17.1054H12.3283C12.2504 17.1054 12.1733 17.089 12.1021 17.0573C12.0309 17.0255 11.9672 16.9792 11.9151 16.9212L9.91339 14.6971C9.86255 14.6432 9.82301 14.5796 9.79708 14.5102C9.77115 14.4408 9.75936 14.3669 9.76239 14.2929C9.76543 14.2188 9.78324 14.1461 9.81478 14.0791C9.84631 14.012 9.89093 13.9519 9.94601 13.9024C10.0011 13.8528 10.0655 13.8147 10.1355 13.7904C10.2055 13.7661 10.2797 13.756 10.3537 13.7608C10.4276 13.7655 10.4999 13.785 10.5662 13.8181C10.6325 13.8512 10.6915 13.8972 10.7398 13.9534L12.3137 15.7021L16.574 10.6315C16.6695 10.521 16.8047 10.4525 16.9503 10.4409C17.096 10.4293 17.2403 10.4755 17.3521 10.5695C17.464 10.6634 17.5344 10.7976 17.5481 10.943C17.5618 11.0885 17.5177 11.2335 17.4254 11.3467V11.3467Z"
fill="#333333" />
</g>
<defs>
<filter id="filter0_d" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" />
<feOffset />
<feGaussianBlur stdDeviation="2.78016" />
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" />
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow" />
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape" />
</filter>
</defs>
</svg>
index.html
<!-- Does not work -->
<img src="./assets/svg-icons.svg#checkMark" alt="design-img" title="design-img">
<!-- Does not work -->
<object type='image/svg+xml'data="./assets/svg-icons.svg#checkMark"> </object>
<!-- Does not work -->
<svg width="27" height="27" viewBox="0 0 27 27" xmlns="http://www.w3.org/2000/svg">
<use xlink:href="./assets/svg-icons.svg#checkMark"></use>
</svg>
<!-- Works! -->
<svg width="27" height="27" viewBox="0 0 27 27" xmlns="http://www.w3.org/2000/svg">
<use xlink:href="./assets/svg-icons.svg#sell-house-vector"></use>
</svg>
<!-- Does not work -->
<svg width="27" height="27" viewBox="0 0 27 27" xmlns="http://www.w3.org/2000/svg">
<use xlink:href="./assets/checkMark.svg"></use>
</svg>
<!-- Works -->
<object type='image/svg+xml'data="./assets/checkMark.svg"> </object>
Please try this: In the ./assets/svg-icons.svg change all the <symbol> in <svg> and add
<style type="text/css">
<![CDATA[
svg > svg:not(:target) {
display: none;
}
]]>
</style>
This is saying that only the targeted nested svg elements should be displayed.
Now in the index.html you should be able to see the image and the object.
Please read about How SVG Fragment Identifiers Work
It's the first time I'm going to use SVG graphics and I'm a bit confused… I've researched extensively but I cannot seem to find an answer to what I'm trying to do.
I want to give an image the following appearance, given the source image is a color image.
The main reason behind this effect is to overcome bad quality images (both in terms of aesthetics and resolution) my clients might upload to their websites.
In Photoshop this is a Gradient Map and a transparent grid in Mode Multiply.
I've managed to apply a filter for the grayscale and "gradient map" but I cannot add the grid/pattern.
This is my code so far:
SVG file gradient-map.svg
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="duotone_filter">
<feColorMatrix type="matrix" result="grayscale"
values="1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
0 0 0 1 0" >
</feColorMatrix>
<feComponentTransfer color-interpolation-filters="sRGB" result="duotone">
<feFuncR type="table" tableValues="0.0039525691 0.5764705882"></feFuncR>
<feFuncG type="table" tableValues="0.0123456790 0.8431372549"></feFuncG>
<feFuncB type="table" tableValues="0.0123456790 0.9803921569"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
</filter>
</svg>
HTML
<div class="image">
<img src="link/to/file" />
</div>
CSS
.image {
filter: url('../images/gradient-map.svg#duotone_filter');
}
And the SVG file for the pattern/fill
<svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="6px" height="6px" viewBox="0 0 6 6">
<circle cx="3" cy="3" r="2" />
</svg>
Is this the way things should be done? How should I proceed to achieve this effect?
If you could also link me to useful resources I would much appreciate. I haven't found any recent guides or articles.
Thanks.
You're on the right track. Here's a demo I put together (and on Codepen). And the output:
There's a helpful question to Overlay grid on responsive image, but I opted for simply overlaying and scaling a large transparent PNG. You'll likely end up with better results if you use a small, repeating grid section. Of course you'll have to choose what color, size, etc. to make the grid overlay.
As a side note, you cannot use the :after or :before pseudo-elements with img elements, so you need to wrap them in a container. You could also accomplish this with an additional element, like:
<div class="img-container">
<img src="..." />
<div class="grid-overlay"></div>
</div>
But I prefer pseudo-elements so I don't have to repeat <div class="grid-overlay"></div> every time I want the grid overlay.
img {
filter: url(#duotone_filter)
}
.img-container {
display: inline-block;
overflow: hidden;
position: relative;
height: 375px;
}
.img-container::after {
content: '';
display: block;
position: absolute;
background-image: url('http://www.freeiconspng.com/uploads/grid-png-31.png');
background-size: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div class="img-container"><img src="http://kb4images.com/images/random-image/37670495-random-image.jpg" /></div>
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="duotone_filter">
<feColorMatrix type="matrix" result="grayscale"
values="1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
0 0 0 1 0" >
</feColorMatrix>
<feComponentTransfer color-interpolation-filters="sRGB" result="duotone">
<feFuncR type="table" tableValues="0.0039525691 0.5764705882"></feFuncR>
<feFuncG type="table" tableValues="0.0123456790 0.8431372549"></feFuncG>
<feFuncB type="table" tableValues="0.0123456790 0.9803921569"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
</filter>
</svg>
Also an example using only SVGs (symbols):
One final example that also works in Firefox and uses two SVG filters. The key to this example is that it uses another filter to create a composite image. I took another SVG from the web but you could use an inline SVG and reference it by ID as well.
<filter id="overlay">
<feImage result="sourceTwo" xlink:href="http://www.vectorstash.com/vectors/vectorstash-grid.svg" width="500" height="375" preserveAspectRatio="none" x="0" y="0" />
<feComposite in="SourceGraphic" in2="sourceTwo" operator="out" x="0" y="0" />
</filter>
A handy way to do this is to combine the grid overlay with the filter by putting inline SVG for the grid into an feImage primitive.
(I also changed your greyscale matrix because it was only using the red channel as source which is going to create weird results on blue/green heavy photos.)
.filterclass {
filter: url(#duotone_filter);
}
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="duotone_filter" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feImage width="6" height="6" xlink:href= "data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20x%3D%220%22%20y%3D%220%22%20width%3D%226px%22%20height%3D%226px%22%20viewBox%3D%220%200%206%206%22%3E%0A%20%20%20%3Crect%20x%3D%220%22%20y%3D%220%22%20width%3D%226%22%20height%3D%226%22%20fill%3D%22none%22%20stroke%3D%22grey%22/%3E%0A%3C/svg%3E"/>
<feTile result="overlay"/>
<feColorMatrix in="SourceGraphic" type="matrix" result="grayscale"
values=".33 .33 .33 0 0
.33 .33 .33 0 0
.33 .33 .33 0 0
0 0 0 1 0" />
<feComponentTransfer result="duotone">
<feFuncR type="table" tableValues="0.0039525691 0.5764705882"></feFuncR>
<feFuncG type="table" tableValues="0.0123456790 0.8431372549"></feFuncG>
<feFuncB type="table" tableValues="0.0123456790 0.9803921569"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
<feBlend mode="multiply" in="overlay"/>
</filter>
</svg>
<div >
<img class="filterclass" src="http://kb4images.com/images/random-image/37670495-random-image.jpg" />
</div>
The source SVG for the inlined data uri is
<svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="6px" height="6px" viewBox="0 0 6 6">
<rect x="0" y="0" width="6" height="6" fill="none" stroke="grey"/>
</svg>
If you want to tweak it - I use this converter for svg+xml - which is pretty useful https://codepen.io/yoksel/details/JDqvs
I have created a nice svg frame by applying filters in Inkscape v 0.91.
I want to apply it to an HTML element too. However I cant. I was expecting that the div element turns into a frame like rect element of svg. Can you explain to me why svg filters did not apply to div element. Many people seem to be able to apply svg filters to html elements.
<html>
<head>
</head>
<body>
<div style="
background-color: aliceblue;
width: 300px;
height: 300px;
filter: url(#aslan);
">Duh ! Its not working </div>
<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="297mm" width="210mm" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" viewBox="0 0 744.09448819 1052.3622047">
<defs>
<filter id="aslan" style="color-interpolation-filters:sRGB">
<feGaussianBlur stdDeviation="0.5" result="result1"></feGaussianBlur>
<feBlend result="result5" mode="normal" in2="result1" in="SourceGraphic"></feBlend>
<feGaussianBlur stdDeviation="3" result="result6" in="result5"></feGaussianBlur>
<feComposite operator="xor" result="result8" in2="result6" in="result6"></feComposite>
<feComposite operator="in" result="fbSourceGraphic" in2="result8" in="result6"></feComposite>
<feColorMatrix values="0 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 1 0 " result="fbSourceGraphicAlpha" in="fbSourceGraphic"></feColorMatrix>
<feGaussianBlur stdDeviation="0.5" result="result0" in="fbSourceGraphic"></feGaussianBlur>
<feSpecularLighting lighting-color="rgb(255,255,255)" specularConstant="2" result="result1" specularExponent="55" in="result0" surfaceScale="2">
<fePointLight y="-10000" x="-5000" z="20000"></fePointLight>
</feSpecularLighting>
<feComposite in2="fbSourceGraphicAlpha" k1="1" result="result2" in="result1" operator="arithmetic"></feComposite>
<feComposite in2="result2" k3="1" k2="0.5" result="result4" in="fbSourceGraphic" operator="arithmetic"></feComposite>
<feComposite operator="over" result="result91" in2="result4" in="result9"></feComposite>
<feBlend result="fbSourceGraphic" mode="screen" in2="result91"></feBlend>
<feColorMatrix values="0 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 1 0" result="fbSourceGraphicAlpha" in="fbSourceGraphic"></feColorMatrix>
<feFlood result="flood" flood-color="rgb(0,0,0)" in="fbSourceGraphic" flood-opacity=".49804"></feFlood>
<feComposite operator="in" result="composite1" in2="fbSourceGraphic" in="flood"></feComposite>
<feGaussianBlur result="blur" stdDeviation="3.6" in="composite1"></feGaussianBlur>
<feOffset result="offset" dx="-12.2396" dy="6"></feOffset>
<feComposite operator="over" result="fbSourceGraphic" in2="offset" in="fbSourceGraphic"></feComposite>
<feColorMatrix values="0 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 1 0" result="fbSourceGraphicAlpha" in="fbSourceGraphic"></feColorMatrix>
<feFlood result="flood" flood-color="rgb(0,0,0)" in="fbSourceGraphic" flood-opacity=".49804"></feFlood>
<feComposite operator="in" result="composite1" in2="fbSourceGraphic" in="flood"></feComposite>
<feGaussianBlur result="blur" stdDeviation="3.6" in="composite1"></feGaussianBlur>
<feOffset result="offset" dx="-12.2" dy="6"></feOffset>
<feComposite operator="over" result="fbSourceGraphic" in2="offset" in="fbSourceGraphic"></feComposite>
<feColorMatrix values="0 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 1 0" result="fbSourceGraphicAlpha" in="fbSourceGraphic"></feColorMatrix>
<feConvolveMatrix divisor="1" kernelMatrix="0 -0.15 0 -0.15 1.6 -0.15 0 -0.15 0" targetY="1" order="3 3" targetX="1" in="fbSourceGraphic"></feConvolveMatrix>
</filter>
</defs>
<rect transform="matrix(.59683 0 0 .59683 72.863 46.68)" height="115.16" filter="url(#aslan)" width="220.21" y="127.3" x="202.74" fill="#0f0"></rect>
</svg>
</body>
</html>
Thank you.
You should add
-webkit-filter: url(#aslan);
to your style definition. So the final style definition should be like this:
<div style="
background-color: aliceblue;
width: 300px;
height: 300px;
filter: url(#aslan);
-webkit-filter: url(#aslan);
">Duh ! Its not working </div>
I need to make a shadow for rect element for svg. The snippet below does the job, but I don't know how to control the color/opacity of the shadow? Any help will be appreciated!
<svg height="120" width="120">
<defs>
<filter id="f1" x="0" y="0" width="200%" height="200%">
<feOffset result="offOut" in="SourceGraphic" dx="20" dy="20" />
<feBlend in="SourceGraphic" in2="offOut" mode="normal" />
</filter>
</defs>
<rect width="90" height="90" stroke="green" stroke-width="3" fill="yellow" filter="url(#f1)" />
Came across this w3schools page with similar examples. Based on the examples given there, it looks like you need to add few more filters (like feColorMatrix and feGaussianBlur) to bring the desired effect.
Your code with new filters:
<svg height="120" width="120">
<defs>
<filter id="f1" x="0" y="0" width="200%" height="200%">
<feOffset result="offOut" in="SourceGraphic" dx="10" dy="10" />
<feColorMatrix result="matrixOut" in="offOut" type="matrix"
values="0.2 0 0 0 0 0 0.2 0 0 0 0 0 0.2 0 0 0 0 0 1 0" />
<feGaussianBlur result="blurOut" in="matrixOut" stdDeviation="10" />
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" /> </filter>
</defs>
<rect width="90" height="90" stroke="green" stroke-width="3" fill="yellow" filter="url(#f1)" />
You can use this jsfiddle also.
Update:
We can achieve opacity & color change just with feColorMatrix filter. Check this updated jsFiddle.
But, in order achieve the desired color you need to understand more about setting values attribute of feColorMatrix.
Following links may be helpful:
Match colors in feColorMatrix filter
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feColorMatrix
SVG Drop Shadow - opacity, feOffset and viewBox difficulties