SVG Blur Effect
In SVG, the blur effect can be achieved through the element, which uses the Gaussian blur algorithm to blur the image.
The blur effect can be used to create various visual effects such as soft shadows, depth of field, and blurred backgrounds.
element:
The element is used to apply Gaussian blur to an image, and it has two main parameters:
-
stdDeviation: Specifies the standard deviation of the Gaussian blur. The larger the standard deviation, the higher the degree of blur. One or two numbers can be used, representing the standard deviations in the horizontal and vertical directions respectively. If only one number is provided, the horizontal and vertical standard deviations are the same. -
in: Specifies the input image, usuallySourceGraphic, indicating the target element itself to which the filter effect is applied.
The following code defines a blur filter and then applies it to a red-filled rectangle, giving the rectangle a blurred effect; stdDeviation="5" means the standard deviations in both the horizontal and vertical directions are 5, i.e. the blur degree is 5 pixels.
Example
Example 1
Below is the SVG code:
Example
Try it »
Click to view:View SVG File.
Code analysis:
The element's id attribute defines a unique name for a filter The element defines the blur effect - The part in="SourceGraphic" defines that the effect is created from the entire image
- The stdDeviation attribute defines the amount of blur
The element's filter attribute is used to link the element to the "f1" filter
Notes
-
The blur effect can be applied to any SVG graphic element, including rectangles, circles, paths, etc.
-
Parameters of the blur effect
stdDeviationcan be adjusted as needed to obtain a suitable degree of blur. -
The blur effect can be combined with other filter effects, such as shadows, blend modes, etc.
By using element, you can add a blur effect to SVG graphic elements, giving them a soft, blurred appearance and thus achieving various visual effects.