SVG+滤镜解决方案
在图像中创建锯齿状边缘的SVG
解决方案不需要使用带有锯齿状边缘的图案的光栅图像。因此,这种 SVG 解决方案可以应用于任何图像并使其具有自适应性。
考虑使用相同的图像创建锯齿状边缘 2 次。过滤器应用于较低的图像,因此,它变得更大一些。原始图像叠加在顶部,因此边缘上的牙齿变得可见。为了只在下边缘留下牙齿,我们在侧边缘用面罩切除了不必要的牙齿。
.container {
width:90vw;
height:90vh;
}
<div class="container">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 1800 900" >
<defs>
<mask id="msk1">
<rect x="100%" y="100%" fill="white" />
<rect x="1700" y="0" width="50" height="900" fill="white" />
</mask>
<filter id="displacementFilter">
<feTurbulence type="turbulence" baseFrequency="0.01 0.01"
numOctaves="2" result="turbulence" seed="1"/>
<feDisplacementMap in2="turbulence" in="SourceGraphic"
scale="65" xChannelSelector="R" xChannelSelector="G" yChannelSelector="B"/>
</filter>
</defs>
<!-- The image is processed by a filter and therefore overall dimensions have increased due to the height of the teeth -->
<image filter="url(#displacementFilter)" xlink:href="https://i.stack.imgur.com/paWbQ.jpg.jpg" width="1700" height="850" />
<rect mask="url(#msk1)" x="1700" y="0" width="50" height="900" fill="white" />
<!-- The same original image, but without filters -->
<image x="0" xlink:href="https://i.stack.imgur.com/paWbQ.jpg.jpg" width="1700" height="850" />
</svg>
</div>
另一个图像
.container {
width:90vw;
height:90vh;
}
<div class="container">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 1800 900" >
<defs>
<mask id="msk1">
<rect x="100%" y="100%" fill="white" />
<rect x="1700" y="0" width="50" height="900" fill="white" />
</mask>
<filter id="displacementFilter">
<feTurbulence type="turbulence" baseFrequency="0.01 0.01"
numOctaves="2" result="turbulence" seed="1"/>
<feDisplacementMap in2="turbulence" in="SourceGraphic"
scale="75" xChannelSelector="R" xChannelSelector="G" yChannelSelector="B"/>
</filter>
</defs>
<!-- The image is processed by a filter and therefore overall dimensions have increased due to the height of the teeth -->
<image filter="url(#displacementFilter)" xlink:href="https://i.stack.imgur.com/kaYSe.jpg" width="1700" height="850" />
<rect mask="url(#msk1)" x="1700" y="0" width="50" height="900" fill="white" />
<!-- The same original image, but without filters -->
<image x="0" xlink:href="https://i.stack.imgur.com/kaYSe.jpg" width="1700" height="850" />
</svg>
</div>