Is there a way to display an image inside SVG Circle ?
I tried adding the image inside Svg element but the image does not appear in the circle.
<svg width="100" height="100">
<circle cx="50" cy="50" r="40"stroke="green" stroke-width="4" fill="yellow" />
<img src="starkeen_ane.jpg"/>
</svg>
Can you help me?
The <image> SVG element includes images inside SVG documents. It can display raster image files or other SVG files. The only image formats SVG software must support are JPEG, PNG, and other SVG files.
To embed an SVG via an <img> element, you just need to reference it in the src attribute as you'd expect. You will need a height or a width attribute (or both if your SVG has no inherent aspect ratio).
You can embed SVG elements directly into your HTML pages.
SVG is, essentially, to graphics what HTML is to text. SVG images and their related behaviors are defined in XML text files, which means they can be searched, indexed, scripted, and compressed. Additionally, this means they can be created and edited with any text editor or with drawing software.
It is maybe not the best way to do it. but it works very good. The thing you can do it place it to a relative position and edit top and left properties so you image is in the center of your svg image. Also important is to place it outside your svg
-tag.
img {
position: relative;
top: -30px;
left: -70px;
}
<svg width="100" height="100">
<circle cx="50" cy="50" r="40"stroke="green" stroke-width="4" fill="yellow" />
</svg>
<img src="http://i.stack.imgur.com/vxCmj.png"/>
Here is an example elaborating on Havenard's comment above:
<svg width="500" height="250">
<defs>
<clipPath id="circleView">
<circle cx="250" cy="125" r="125" fill="#FFFFFF" />
</clipPath>
</defs>
<image
width="500"
height="250"
xlink:href="https://www.amrita.edu/sites/default/files/news-images/new/news-events/images/l-nov/grass.jpg"
clip-path="url(#circleView)"
/>
</svg>
You don't actually draw a <circle>
element with an image inside - instead, define a circular clip path, and set it as the 'clip-path' attribute on the <image>
tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With