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

SVG: linearGradient elements don't have unique ids, so there's "colour bleeding" between SVG flags #66

Open
horeamarc opened this issue Nov 22, 2018 · 4 comments

Comments

@horeamarc
Copy link

horeamarc commented Nov 22, 2018

There are a lot of flags with linear gradients, which are give ids like "linearGradient-1".."linearGradient-n".

So, let's say you have the AR flag, followed by RO.
AR has two linear-gradient elements: id="linearGradient-1" and id="linearGradient-2"
RO has 3: id="linearGradient-1", id="linearGradient-2" and id="linearGradient-3"

In this case, if they are on the same HTML page, the RO flag will use the gradients 1 and 2 from the AG file:
AG: image => RO: image, AUS: image, UK: image

@blommegard
Copy link
Member

Uh, this is not that nice at all. I guess the best way to solve this would be to go over each flag and assign random id fields to each of them?

@horeamarc
Copy link
Author

Uh, this is not that nice at all. I guess the best way to solve this would be to go over each flag and assign random id fields to each of them?

Yes, that was my initial thought...to use unique IDs...but then I've switched to use the PNG ones, instead.
Thanks for your thoughts.

@blommegard
Copy link
Member

Uh, this is not that nice at all. I guess the best way to solve this would be to go over each flag and assign random id fields to each of them?

Yes, that was my initial thought...to use unique IDs...but then I've switched to use the PNG ones, instead.
Thanks for your thoughts.

Thanks for the reply, and happy that the png option worked.
Might still be something to think about doing to help others tho.

@sandgraham
Copy link

One solution is to use an svg optimization library such as svgo to prefix all the IDs with a code unique to each SVG.

Here is some example code (for Node) that I used in my own project. You can generalize this to run over each file, but the main bit is to use the cleanupIDs plugin with svgo.

const fs = require('fs');
const SVGO = require('svgo');

// Processing US only

const svgo = new SVGO({
  plugins: {
    // lots of plugins & optimizations available
    cleanupIDs: {
      prefix: 'US'
    }
  }
});

const svgUS = fs.readFileSync('./US.svg').toString();
svgo.optimize(svgUS).then(res => {
  fs.writeFileSync('./optimized/US.svg', res.data);
}) ;

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

No branches or pull requests

3 participants