1. 程式人生 > >如何用SVG做出背景填充效果(avatar)

如何用SVG做出背景填充效果(avatar)

在繪製圖譜時,需要在圓圈中填充圖片,且不能重複,效果如下:
SVG背景填充效果
實現的程式碼如下:

<defs>
    <!-- 這裡的width、height都是相對的比例,所以1也代表100% -->
    <pattern id="patter-0" height="1" width="1" patternContentUnits="objectBoundingBox">
        <!-- 這裡的width、height是相對圖片的真實大小,數字越大,顯示的區域越小 -->
        <image height="1" width="1"
preserveAspectRatio="none" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/static/6.jpg">
</image> </pattern> </defs> <circle r="45" fill="url(#patter-0)" stroke="green" stroke-width="4" cx="827.2632523876052" cy="347.44349874265436" > </circle>