-
Notifications
You must be signed in to change notification settings - Fork 324
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
Comments
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 the reply, and happy that the png option worked. |
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 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);
}) ; |
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: => RO: , AUS: , UK:
The text was updated successfully, but these errors were encountered: