Home >Web Front-end >CSS Tutorial >How to Resize an Image for a Circular SVG Mask Fit?
Resizing an Image to Fit a Circular SVG Path
When attempting to cut a circular part from an image using an SVG path, it's important to ensure proper alignment. If the image doesn't fit well, it might be due to incorrect sizing or positioning of the SVG mask.
Here's an alternative approach to achieve the desired result:
Enhancement Using an SVG Mask:
This method employs an SVG mask to create a circular hole within which the image is displayed:
<code class="svg"><svg width="200" height="200"> <defs> <mask id="hole"> <circle r="100" cx="100" cy="100" fill="white"/> <circle r="50" cx="180" cy="180" fill="black"/> </mask> <pattern id="img" patternUnits="userSpaceOnUse" width="200" height="200"> <image xlink:href="https://picsum.photos/200/200?image=1069" x="0" y="0" width="200" height="200" /> </pattern> </defs> <!-- Create a rect, fill it with the image and apply the mask --> <rect fill="url(#img)" width="100%" height="100%" mask="url(#hole)" /> </svg></code>
Explanation:
Using this enhanced approach, the image should now fit properly within the circular SVG mask.
The above is the detailed content of How to Resize an Image for a Circular SVG Mask Fit?. For more information, please follow other related articles on the PHP Chinese website!