You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Considering this repository is called flag-icons, one might assume that most consumers use the flags as icons, which means pretty small on-screen sizes. Probably around 30x30 pixels or similar, usually. So miniscule details are probably not required or desired.
I think it's ok that some obscure, uncommon flags are large in filesize, as they are probably infrequently used. But some common flags are quite heavy in filesize - most notably Mexico and Spain (89 KB and 93 KB).
This is because they are extremely detailed in some decorative elements. Having lots of tiny details not only increases file size, but also the CPU load of parsing and drawing the SVG.
Proposed solutions
Merging many small paths into big paths
SVGO has a plugin for that. But studying the plugin code I've found that it requires that path elements come after each other and have exactly the same attributes.
I think some of the large flags do have many elements with matching attributes, but have alternating fill and stroke paths, causing them to be non-mergeable. This might be a reason SVGO compression doesn't work as well as it could.
If one could sort the fill/stroke/stroke-width elements so that they are grouped together, SVGO optimizations might give good results.
Removing superflous elements
Removing superflous elements that are practically invisibile at sub-100px size. This could be tricky at times because sometimes very small individual paths together make up a big important part of the flag. Therefore one might want to merge paths before deciding which paths are superflous.
Reduce path complexity
Reducing path complexity by using simplify-svg-path or similar tools. I tried this and there were issues with paths that have more than one Move command. The path simplifier can't handle moves beyond the first one causing lines to be drawn between segments.
Approximate major graphical elements
Manually extract certain graphical elements and run them through some sort of approximator tool that generates a path that outlines the entire shape. For example a big detailed eagle might become a single, quite simple path that still looks very much like a nice eagle at sub-100px sizes.
Screenshots showing many alternating strokes/fills (Spain flag):
The text was updated successfully, but these errors were encountered:
While it is true a lot of users use them in resolutions smaller than 100x100, there are users at higher resolutions, and these are intentionally designed as SVGs to support multiple resolutions. There was a point in time where I was going through the largest flags and attempting to optimize where possible, but I haven't had the bandwidth to continue that endeavor recently. Unfortunately, one of the larger optimizations that we tried a while back caused issues when used in React Native.
These are SVG flags and as close to official as possible..! If size matter in your case convert them to small pngs or something.. but we won't alter the flags just because of the size..! We are relying on SVGO to make them smaller, but that's it..
Hello!
Thanks for an amazing library.
Considering this repository is called flag-icons, one might assume that most consumers use the flags as icons, which means pretty small on-screen sizes. Probably around 30x30 pixels or similar, usually. So miniscule details are probably not required or desired.
I think it's ok that some obscure, uncommon flags are large in filesize, as they are probably infrequently used. But some common flags are quite heavy in filesize - most notably Mexico and Spain (89 KB and 93 KB).
This is because they are extremely detailed in some decorative elements. Having lots of tiny details not only increases file size, but also the CPU load of parsing and drawing the SVG.
Proposed solutions
Merging many small paths into big paths
SVGO has a plugin for that. But studying the plugin code I've found that it requires that path elements come after each other and have exactly the same attributes.
I think some of the large flags do have many elements with matching attributes, but have alternating fill and stroke paths, causing them to be non-mergeable. This might be a reason SVGO compression doesn't work as well as it could.
If one could sort the fill/stroke/stroke-width elements so that they are grouped together, SVGO optimizations might give good results.
Removing superflous elements
Removing superflous elements that are practically invisibile at sub-100px size. This could be tricky at times because sometimes very small individual paths together make up a big important part of the flag. Therefore one might want to merge paths before deciding which paths are superflous.
Reduce path complexity
Reducing path complexity by using simplify-svg-path or similar tools. I tried this and there were issues with paths that have more than one Move command. The path simplifier can't handle moves beyond the first one causing lines to be drawn between segments.
Approximate major graphical elements
Manually extract certain graphical elements and run them through some sort of approximator tool that generates a path that outlines the entire shape. For example a big detailed eagle might become a single, quite simple path that still looks very much like a nice eagle at sub-100px sizes.
Screenshots showing many alternating strokes/fills (Spain flag):
The text was updated successfully, but these errors were encountered: