Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a background image (.png) to a SVG circle shape

Tags:

html

css

svg

Is this possible? The following is what I tried but it completely fills the circle with black.

<svg id='vizMenu' width="700" height="660">     <defs>         <filter id="dropshadow" height="130%">             <feGaussianBlur in="SourceAlpha" stdDeviation="2"/>              <feOffset dx="0.5" dy="0.8" result="offsetblur"/>              <feMerge>                 <feMergeNode/>                 <feMergeNode in="SourceGraphic"/>             </feMerge>         </filter>     </defs>     <circle id='top' filter="url(#dropshadow)" cx="180" cy="120" r="80" stroke="#2E2E2E" stroke-width="2" fill="url('images/word-cloud.png')"/>     <circle id='bottom' filter="url(#dropshadow)" cx="500" cy="300" r="80" stroke="#2E2E2E" stroke-width="2" fill="url('images/word-cloud.png')"/>     <circle id='extra' filter="url(#dropshadow)" cx="180" cy="560" r="80" stroke="#2E2E2E" stroke-width="2" fill="#ffffff"/> </svg> 
like image 396
icanc Avatar asked Jul 16 '12 00:07

icanc


People also ask

How do I add a background to a SVG circle?

To set the background color for the circle SVG element, you can use the fill attribute on the circle element inside the svg tag in HTML.

Can an SVG have a background image?

After you place your file path or SVG code into the background-image property, you can further tweak how the background displays. You see, the great thing about using an SVG as a CSS background-image is that they can be styled with CSS background properties.


1 Answers

An image fill for an svg element is achieved through SVG Patterns...

<svg width="700" height="660">   <defs>     <pattern id="image" x="0" y="0" patternUnits="userSpaceOnUse" height="1" width="1">       <image x="0" y="0" xlink:href="url.png"></image>     </pattern>   </defs>   <circle id='top' cx="180" cy="120" r="80" fill="url(#image)"/> </svg> 
like image 122
methodofaction Avatar answered Nov 08 '22 06:11

methodofaction