Warm tip: This article is reproduced from serverfault.com, please click

html-带有feGaussianBlur stdDeviation的SVG形状无法在Google Chrome上正确呈现

(html - SVG shapes with feGaussianBlur stdDeviation not rendering correctly on google chrome)

发布于 2020-12-21 17:37:09

所以我在图像上使用了SVG蒙版,使边缘的椭圆变得模糊,有一段时间它在所有浏览器上看起来都是正确的,但随后在svg上的模糊效果在chrome和microsoft边缘上看起来确实是错误的,我不知道为什么它正在发生或解决了问题。我正在使用feGaussianBlur stdDeviation标记为其提供模糊的边缘,并且它们显然在每个浏览器上都执行不同的操作。(Firefox看起来应该是这样)。有人请指引我正确的方向:)

这是我用来制作遮罩图像的代码

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400px" height="350px" class="rotating">
  <defs>
    <filter id="filter">
      <feGaussianBlur stdDeviation="20" />
    </filter>
    <mask id="mask">
      <ellipse cx="50%" cy="50%" rx="35%" ry="35%" fill="white" filter="url(#filter)"></ellipse>
    </mask>
  </defs>
                
                <image class="homepage-header-image " xlink:href="http://legendbranding.com/wp-content/uploads/2020/11/cropped-ryan-plomp-0iPebSCgKoA-unsplash-3.jpg" mask="url(#mask)"></image>
                </svg>
            </div>



<script>
     .header-description.media-on-right img.homepage-header-image {
        float: right;
      }
</script>

Firefox中的SVG

Chrome中的SVG

Questioner
Mark Btesh
Viewed
0
Michael Mullany 2021-01-05 07:51:32

Chrome中的遮罩和滤镜之间似乎存在交互错误。你可以通过使用feComposite在滤镜内进行遮罩并反转蒙版和图像的顺序来避免这种情况:使用feImage将图像拉入滤镜,然后使用SourceGraphic定义遮罩。

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400px" height="350px" >
  <defs>
    <filter id="myfilter" filterUnits="userSpaceOnUse" x="0" y="0" width="400" height="350">
      <feGaussianBlur stdDeviation="20" result="reverse-mask"/>
      <feImage x="0" y="0" width="400"
 height="350"  preserveAspectRatio="none" xlink:href="https://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Wilsons_Promontory_National_Park_%28AU%29%2C_Big_Drift_--_2019_--_1683.jpg/1280px-Wilsons_Promontory_National_Park_%28AU%29%2C_Big_Drift_--_2019_--_1683.jpg"/>
      <feComposite operator="in" in2="reverse-mask"/>
    </filter>
      </defs>
  
      <g filter="url(#myfilter)">
      <ellipse cx="50%" cy="50%" rx="35%" ry="35%" fill="white" />
      </g>

 </svg>

(ps最好发布带有有效图像URL的完整的自包含工作代码,例如,如果CSS类不相关,则删除它们。)