Learning SVG series (4): SVG filter effects

Source: Internet
Author: User

Note: Internet Explorer and Safari do not support SVG filters

<defs>, <filter>

All Internet SVG filters are defined in the <defs> element,<filter> tags are used to define the SVG filter,<filter> label using the required ID attribute to define the apply to the image in the filter

SVG Blur effect

<feGaussianBlur>

The Fegaunssianblur element is used to create a blur effect

SVG code:

<svg xmlns= "Http://www.w3.org/2000/svg" version= "1.1" >
<defs>
<filter id= "F1" x= "0" y= "0" >
<fegaussianblur in= "sourcegraphic" stddeviation= "/>"
</filter>
</defs>
<rect width= "height=" stroke= "Green" stroke-width= "3"
Fill= "yellow" filter= "url (#f1)"/>
</svg>

Code parsing:

<filter> Element ID attribute defines a unique name for a filter

<feCaussianBlur> element definition Blur effect

The in= "sourcegraphic" section defines the effect created by the entire image.

Stddeviation property defines the amount of blur

The filter attribute of the <rect> element is used to link elements to the "F1" filter

SVG shadows

<feOffset>

Feoffset elements for creating shadow effects

Example 1

Offset a rectangle (with <feOffset>) and then blend the top of the image (with <feBlend>)

SVG code:

<svg xmlns= "Http://www.w3.org/2000/svg" version= "1.1" >
<defs>
<filter id= "F1" x= "0" y= "0" width= "200%" height= "200%" >
<feoffsetresult= "Offout" in= "sourcegraphic" dx= "the Dy=" "/>"
<feblendin= "Sourcegraphic" in2= "offout" mode= "normal"/>
</filter>
</defs>
<rect width= "height=" stroke= "Green" stroke-width= "3"
Fill= "yellow" filter= "url (#f1)"/>
</svg>

Example 2

The offset image can be blurred (including <feGaussianBlur>)

SVG code:

<svgxmlns= "Http://www.w3.org/2000/svg" version= "1.1" >
<defs>
<filter id= "F1" x= "0" y= "0" width= "200%" height= "200%" >
<feoffsetresult= "Offout" in= "sourcegraphic" dx= "the Dy=" "/>"
<fegaussianblur result= "Blurout" in= "offout" stddeviation= "/>"
<feblendin= "Sourcegraphic" in2= "blurout" mode= "normal"/>
</filter>
</defs>
<rect width= "height=" stroke= "Green" stroke-width= "3"
Fill= "yellow" filter= "url (#f1)"/>
</svg>

Code parsing

The stddeviation attribute of the element defines the amount of blur

Example 3

Make a black Shadow

SVG code:

<svgxmlns= "Http://www.w3.org/2000/svg" version= "1.1" >
<defs>
<filter id= "F1" x= "0" y= "0" width= "200%" height= "200%" >
<feoffsetresult= "Offout" in= "Sourcealpha" dx= "the Dy=" "/>"
<fegaussianblur result= "Blurout" in= "offout" stddeviation= "/>"
<feblendin= "Sourcegraphic" in2= "blurout" mode= "normal"/>
</filter>
</defs>
<rect width= "height=" stroke= "Green" stroke-width= "3"
Fill= "yellow" filter= "url (#f1)"/>
</svg>

Code parsing:

The attribute of the Feoffset element is changed to "Sourcealpha" in the alpha channel using the ghost instead of the entire RGBA pixel

Example 4

Apply a layer of color to the shadow

SVG code:

<svgxmlns= "Http://www.w3.org/2000/svg" version= "1.1" >
<defs>
<filter id= "F1" x= "0" y= "0" width= "200%" height= "200%" >
<feoffsetresult= "Offout" in= "sourcegraphic" dx= "the Dy=" "/>"
<fecolormatrixresult= "Matrixout" in= "Offout" type= "Matrix"
values= "0.20 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= "/>"
<feblendin= "Sourcegraphic" in2= "blurout" mode= "normal"/>
</filter>
</defs>
<rect width= "height=" stroke= "Green" stroke-width= "3"
Fill= "yellow" filter= "url (#f1)"/>
</svg>

Learning SVG series (4): SVG filter effects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.