How to add different background image (.png) to a SVG circle shape , and set stroke?

CloudChing

i alreay see the Add a background image (.png) to a SVG circle shape

but in my case ,i need to add stroke and stroke-width in different image shape

this is my code:

<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>   
    <pattern id="image2" x="0" y="0" patternUnits="userSpaceOnUse" height="1" width="1">
      <image x="0" y="0" xlink:href="url2.png"></image>
    </pattern>   
</defs>   
 <circle cx = "20%" cy = "20%" r = "20" fill = "url(#image)"  stroke-width ="2px" stroke="red"/> 
 <circle cx = "40%" cy = "20%" r = "20" fill = "url(#image2)"  stroke-width ="2px" stroke="red"/>
</svg>

this could not work,the second circle has no image for its fill

and this:

<svg width="700" height="660">
    <filter id="this_image" x="0%" y="0%" width="100%" height="100%">
        <feImage xlink:href="test_image.png"/>
    </filter>
    <circle filter="url(#this_image)" cx="180" cy="120" r="80" stroke-width ="2px" stroke="red"/>
</svg>

the stroke and stroke-width is useless

how can i do? i just want to show different image(ps:circle shape) and add different outline

Alexander

Use objectBoundingBox in patternUnits attribute value instead of userSpaceOnUse. Also you need to declare xlink namespace. Thus, try to use following:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="700" height="660">   
  <defs>
    <pattern id="image" x="0" y="0" patternUnits="objectBoundingBox" height="1" width="1">
      <image x="0" y="0" xlink:href="https://www.gravatar.com/avatar/31497e3c546c438c4eea4b68d6f9f027?s=32&d=identicon&r=PG&f=1"></image>
    </pattern>   
    <pattern id="image2" x="0" y="0" patternUnits="objectBoundingBox" height="1" width="1">
      <image x="0" y="0" xlink:href="https://lh5.googleusercontent.com/-x_BhuHcC8Ww/AAAAAAAAAAI/AAAAAAAAABg/hiPWIjRXbhI/photo.jpg?sz=64"></image>
    </pattern>   
  </defs>   
  <circle cx = "20%" cy = "20%" r = "20" fill = "url(#image)"  stroke-width ="2px" stroke="red"/> 
  <circle cx = "40%" cy = "20%" r = "20" fill = "url(#image2)"  stroke-width ="2px" stroke="red"/>
</svg>

If you run the code snippet, then you will see, that your profile icon is displayed in first circle, and my - in the second.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to add stroke around whole circle and animate to rotate circle in svg?

From Dev

How to add stroke/outline to transparent PNG image in JavaScript canvas

From Dev

How to set image on center of svg circle?

From Dev

Fabric.js - Transparent background on circle shape with stroke/border

From Dev

SVG Circle Stroke Origin

From Dev

SVG Circle Stroke Origin

From Dev

How to set Visibility of Stroke of a Shape in WPF

From Dev

Set image background to shape on JavaScript

From Dev

Stroke created of shape or image

From Dev

How to add a colored background to PNG or add a Color overlay to an Image?

From Dev

How to set background image on the right hand side of a shape in android

From Dev

How to set Circle image?

From Dev

Animated SVG, circle stroke hover

From Dev

Double stroke color of circle in svg

From Dev

How to set opacity to png image with transparent background using Magick++

From Dev

How can I add a background to my png image?

From Dev

How to add a repeating png image in the background of a webpage using CSS?

From Dev

How can I add a background to my png image?

From Dev

Animating circle stroke SVG - Not a full circle

From Dev

Using SVG with referenced PNG as background image

From Dev

How to add a circle to svg element

From Dev

How to crop image in a circle shape in Titanium?

From Dev

Add color and image to fill of SVG circle

From Dev

Is there a way to set stroke behind shape

From Java

Add a background image to shape in XML Android

From Dev

How to dynamically set color of an SVG created by background-image?

From Dev

How to cut the png image as per the shape?

From Java

How to set image in circle in swift

From Dev

SVG - Different stroke width on different svg items

Related Related

  1. 1

    How to add stroke around whole circle and animate to rotate circle in svg?

  2. 2

    How to add stroke/outline to transparent PNG image in JavaScript canvas

  3. 3

    How to set image on center of svg circle?

  4. 4

    Fabric.js - Transparent background on circle shape with stroke/border

  5. 5

    SVG Circle Stroke Origin

  6. 6

    SVG Circle Stroke Origin

  7. 7

    How to set Visibility of Stroke of a Shape in WPF

  8. 8

    Set image background to shape on JavaScript

  9. 9

    Stroke created of shape or image

  10. 10

    How to add a colored background to PNG or add a Color overlay to an Image?

  11. 11

    How to set background image on the right hand side of a shape in android

  12. 12

    How to set Circle image?

  13. 13

    Animated SVG, circle stroke hover

  14. 14

    Double stroke color of circle in svg

  15. 15

    How to set opacity to png image with transparent background using Magick++

  16. 16

    How can I add a background to my png image?

  17. 17

    How to add a repeating png image in the background of a webpage using CSS?

  18. 18

    How can I add a background to my png image?

  19. 19

    Animating circle stroke SVG - Not a full circle

  20. 20

    Using SVG with referenced PNG as background image

  21. 21

    How to add a circle to svg element

  22. 22

    How to crop image in a circle shape in Titanium?

  23. 23

    Add color and image to fill of SVG circle

  24. 24

    Is there a way to set stroke behind shape

  25. 25

    Add a background image to shape in XML Android

  26. 26

    How to dynamically set color of an SVG created by background-image?

  27. 27

    How to cut the png image as per the shape?

  28. 28

    How to set image in circle in swift

  29. 29

    SVG - Different stroke width on different svg items

HotTag

Archive