如何将SVG图像中间紫色区域挖空设为透明?求工具推荐
Absolutely! You can fix this by removing the overlapping yellow area exactly where the purple region sits—this way, when you set the purple to transparent, there’s no yellow underneath to show through. This is done using boolean operations (specifically a "subtract" or "difference" action) on the SVG paths, and there are several tools to make this easy:
GUI Tools (No Code Needed)
These tools let you visually edit the SVG and apply path operations in a few clicks:
- Inkscape (Free, Open Source)
- Open your SVG file.
- Select both the yellow background shape and the purple foreground shape.
- Go to
Path > Difference(this will subtract the purple shape from the yellow one, leaving a hole where the purple was). - Delete the original purple shape, and the hole will now be fully transparent.
- Adobe Illustrator (Paid)
- Import the SVG and select both the yellow and purple paths.
- Open the Pathfinder panel (Window > Pathfinder).
- Click the Minus Front button (this removes the top shape—purple—from the bottom shape—yellow).
- Delete the purple path, and you’ll have a transparent hole in the yellow layer.
- Figma (Free/Paid, Browser-Based)
- Upload the SVG to Figma.
- Select the yellow shape first, then hold Shift and select the purple shape.
- Right-click and choose
Path > Subtract(or use the keyboard shortcut). - Remove the purple shape, and the hole will be transparent.
Manual SVG Code Editing
If you prefer working directly with the SVG markup, you can use a <clipPath> or create a new path that’s the result of the yellow shape minus the purple shape:
- Locate the
dattribute values for both the yellow and purple paths in your SVG code. - Use a path difference tool (free online options are available) to generate a new
dvalue that represents the yellow shape with the purple area removed. - Replace the yellow path’s
dattribute with this new value, then delete the purple path entirely.
Alternatively, you can use a mask for more control:
<defs> <mask id="purpleHole"> <rect width="100%" height="100%" fill="white"/> <!-- White = visible area --> <path d="YOUR_PURPLE_PATH_D_VALUE" fill="black"/> <!-- Black = transparent hole --> </mask> </defs> <!-- Apply the mask to your yellow path --> <path d="YOUR_YELLOW_PATH_D_VALUE" mask="url(#purpleHole)"/>
Either method will ensure the middle area is truly transparent, with no yellow peeking through once you remove the purple layer.
内容的提问来源于stack exchange,提问作者Meeppreave

