svgo icon indicating copy to clipboard operation
svgo copied to clipboard

Combining multiple shapes into a <path> breaks <linearGradient>

Open andersk opened this issue 5 years ago • 2 comments

svgo combines multiple shapes sharing the same <linearGradient> into a single <path>. This happens in the mergePaths plugin, and visually changes the result since the gradient stops are relative to the bounding box of the shape to which the gradient is applied (with the default gradientUnits="objectBoundingBox").

Input

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 100">
    <linearGradient id="gradient">
        <stop offset="0" stop-color="#ff0000" />
        <stop offset="1" stop-color="#0000ff" />
    </linearGradient>
    <path fill="url(#gradient)" d="M 0 0 H 100 V 100 H 0 z" />
    <path fill="url(#gradient)" d="M 200 0 H 300 V 100 H 200 z" />
</svg>

in

Output

(Indentation restored for clarity.)

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 100">
    <linearGradient id="a">
        <stop offset="0" stop-color="red"/>
        <stop offset="1" stop-color="#00f"/>
    </linearGradient>
    <path fill="url(#a)" d="M0 0h100v100H0zM200 0h100v100H200z"/>
</svg>

out

andersk avatar Jul 15 '20 04:07 andersk

is there any project that convert images to svg with gradient?

jadsongmatos avatar Jul 24 '20 22:07 jadsongmatos

This is somewhat similar to #1217.

Should the mergePaths plugin be disabled by default?

andersk avatar Oct 15 '21 04:10 andersk