简体   繁体   English

如何将 svg 形状屏蔽为 svg 图像

[英]how to mask an svg shape to an svg image

So basically I have a triangular shape and I want to mask it in an image/gif.所以基本上我有一个三角形,我想用图像/gif遮盖它。

 <svg width="209" height="143" viewBox="0 0 209 143" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M104.5 0L0.143921 142.5H208.856L104.5 0ZM104.5 10.1551L11.9747 136.5H197.025L104.5 10.1551Z" fill="black"/> </svg> <div class="clipSvg2"> <svg viewBox="0 0 300 300" fill="none" xmlns="http://www.w3.org/2000/svg"> <defs> <mask id="mask11"> <!-- <svg width="209" height="143" viewBox="0 0 209 143" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M104.5 0L0.143921 142.5H208.856L104.5 0ZM104.5 10.1551L11.9747 136.5H197.025L104.5 10.1551Z" fill="black"/> </svg> --> </mask> </defs> //Here add some mask=url(#mask11) <image width="100%" height="100%" xlink:href="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQU69UnQwUGs3VTS51AEM2MRTHED0PRl0rMLVw3hdS_95xNdTPqY5_7E3N-pzgp49lrdkY&usqp=CAU"></image> </svg> </div>

As you see I'm trying to mask the mask11 in my image but I can't do that..I've search a lot here and its not really working I don't know how or what to do about it can anyone help me?如您所见,我正在尝试掩盖image中的mask11 ,但我不能这样做..我在这里搜索了很多,但它并没有真正起作用我不知道如何或该怎么做任何人都可以提供帮助我? Thanks a lot.非常感谢。

I'm not sure what it should look like, but here are two examples.我不确定它应该是什么样子,但这里有两个例子。 The first uses a clip-path.第一个使用剪辑路径。 With the clip-rule="evenodd" it is only the "frame" that shows.使用clip-rule="evenodd"它只是显示的“框架”。 The second is a mask.第二个是面具。 In the mask the path has a white fill – that is what makes the image show.在蒙版中,路径有一个白色填充——这就是图像显示的原因。

In both cases I made the viewBox the same aspect ratio as the image to make the image take up the entire space of the SVG.在这两种情况下,我都将 viewBox 设置为与图像相同的纵横比,以使图像占据 SVG 的整个空间。

 <svg width="300" viewBox="0 0 284 178" xmlns="http://www.w3.org/2000/svg"> <defs> <clipPath id="cp1"> <path clip-rule="evenodd" d="M104.5 0L0.143921 142.5H208.856L104.5 0ZM104.5 10.1551L11.9747 136.5H197.025L104.5 10.1551Z" /> </clipPath> </defs> <image width="100%" height="100%" href="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQU69UnQwUGs3VTS51AEM2MRTHED0PRl0rMLVw3hdS_95xNdTPqY5_7E3N-pzgp49lrdkY&usqp=CAU" clip-path="url(#cp1)"/> </svg> <svg width="300" viewBox="0 0 284 178" xmlns="http://www.w3.org/2000/svg"> <defs> <mask id="m1"> <path d="M104.5 0L0.143921 142.5H208.856L104.5 0ZM104.5 10.1551L11.9747 136.5H197.025L104.5 10.1551Z" fill="white"/> </mask> </defs> <image width="100%" height="100%" href="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQU69UnQwUGs3VTS51AEM2MRTHED0PRl0rMLVw3hdS_95xNdTPqY5_7E3N-pzgp49lrdkY&usqp=CAU" mask="url(#m1)"/> </svg>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM