SVG 过滤器中的大模糊在 Safari 中不起作用

Tho*_*man 3 css svg svg-filters

我已经使用以下 SVG 过滤器代替filter: blur(#px);了一段时间,因为我需要一个模糊覆盖元素边缘到边缘而不是通常的脱落。它在桌面和 Android 上的 Chrome 中都能很好地工作。

另一方面,Safari webkit 有很多问题。我已经尝试删除和调整feColorMatrixfeComposite但结果更糟。

我四处寻找替代品,但我已经完全干了。

<filter id="ultraBlur" width="150%" height="150%" x="-25%" y="-25%" color-interpolation-filters="sRGB">
    <feGaussianBlur stdDeviation="70"></feGaussianBlur>
    <feColorMatrix type="matrix" values="1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 9 0"></feColorMatrix>
    <feComposite in2="SourceGraphic" operator="in"></feComposite>
</filter>
Run Code Online (Sandbox Code Playgroud)

由 chrome 渲染


由 chrome 渲染


由 safari webkit 呈现


由 safari webkit 呈现

Mic*_*any 9

您遇到了 webkit 内存管理启发式方法。根据实验 - 在我的示例图像上,单次传递中的最大模糊大小是 stdDeviation 45 - 大于这个并且 webkit 缩小了图像(以节省内存 - 这是一个巨大的模糊)。

好的 - 你有两个选择。

  1. 通过向过滤器元素添加“filterRes="1200”来强制 webkit 不缩小图像。
  2. 将模糊分成两个步骤以获得相同的效果。

我推荐策略 #2 - 因为 filterRes 现在已被弃用并且只适用于 iOS/Safari(因为 Apple 没有跟上最新的 SVG 内容。)以下在 iOS/Safari 中工作得很好

<svg width="800px" height="600px">
  <defs>
  <filter id="ultraBlur" width="150%" height="150%" x="-25%" y="-25%" color-interpolation-filters="sRGB">
    <feGaussianBlur stdDeviation="45"/>
    <feColorMatrix type="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0 0 0 0 10 0"/>
    <feGaussianBlur stdDeviation="45"/>
     <feColorMatrix type="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0 0 0 0 10 0"/>
    <feComposite in2="SourceGraphic" operator="in"></feComposite>
</filter>
  </defs>
  <image filter="url(#ultraBlur)" x="0" y="0" width="700" height="400" xlink:href="https://upload.wikimedia.org/wikipedia/commons/5/5b/Paris-sunset-panoramic.jpg" preserveAspectRatio="xMidYMid slice"/>
</svg>
Run Code Online (Sandbox Code Playgroud)