Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
andersk opened this issue Jul 15, 2020 · 2 comments · Fixed by #1964
Closed

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

andersk opened this issue Jul 15, 2020 · 2 comments · Fixed by #1964

Comments

@andersk
Copy link

andersk commented Jul 15, 2020

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

@jadsongmatos
Copy link

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

@andersk
Copy link
Author

andersk commented Oct 15, 2021

This is somewhat similar to #1217.

Should the mergePaths plugin be disabled by default?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants