I have an SVG shape (a parallelogram) which is filled with an image. The demo can be seen here.
The SVG object is:
<svg style="overflow:visible; margin-left:111px; margin-top:22px; " height="86" width="281">
<defs>
<pattern id="blip1" patternUnits="userSpaceOnUse" width="279" height="83">
<image xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://i.imgur.com/uTDpE6J.jpg" width="279" height="83"></image>
</pattern>
</defs>
<polygon points="49,2 280,2 232,84 1,84" x="1" y="1" style="stroke-linejoin:round; fill:url(#blip1); stroke-width:2; stroke:hsl(212,45%,26%); "></polygon>
</svg>
But the image is not stretched to the bounds of the shape, instead it lies in the middle of the shape.
What I am trying to achieve is this:
But what I am getting is this:
Can anyone suggest me a solution that will apply to all shapes (i.e. pentagon, hexagon, star etc.)? BTW it already works fine with ellipses.
Adding preserverAspectRatio=none
to the image object and setting width/height to 100% seems to do what you want. Updated fiddle
<svg style="overflow:visible; margin-left:111px; margin-top:22px; " height="86" width="281">
<defs>
<pattern id="blip1" patternUnits="userSpaceOnUse" width="279" height="83">
<image preserveAspectRatio="none" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://i.imgur.com/uTDpE6J.jpg" width="279" height="83"></image>
</pattern>
</defs>
<polygon points="49,2 280,2 232,84 1,84" x="1" y="1" style="stroke-linejoin:round; fill:url(#blip1); stroke-width:2; stroke:hsl(212,45%,26%); ">
</polygon>
</svg>
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