Home > Web Front-end > CSS Tutorial > How to Cut Circular Image Sections Using SVG Paths: A Comprehensive Guide

How to Cut Circular Image Sections Using SVG Paths: A Comprehensive Guide

Mary-Kate Olsen
Release: 2024-10-23 14:48:01
Original
517 people have browsed it

How to Cut Circular Image Sections Using SVG Paths: A Comprehensive Guide

Cutting Circular Images with SVG

In your attempt to cut a circular part of an image using an SVG path, you encountered misalignment. To achieve your desired result, an alternative method using SVG provides a simpler solution.

Here is the code:

<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 above mask -->
  <rect fill="url(#img)" width="100%" height="100%" mask="url(#hole)" />
</svg>
Copy after login

This SVG method involves creating a mask with a circular hole and a pattern with the image. A rectangle is then filled with the image pattern and masked with the hole. This results in a circular cutout of the image within the SVG container.

The above is the detailed content of How to Cut Circular Image Sections Using SVG Paths: A Comprehensive Guide. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template