mirror of
https://github.com/lipis/flag-icons.git
synced 2026-04-26 01:15:55 +03:00
[GH-ISSUE #1236] Mexico and Spain flags are extremely detailed and large in file size #571
Labels
No labels
3rd-party
3rd-party
bug
code
documentation
enhancement
fixed-in-master
flag-request
help needed
missing-flag
missing-flag
pull-request
wrong-flag
wrong-flag
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/flag-icons#571
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @magwo on GitHub (Apr 29, 2024).
Original GitHub issue: https://github.com/lipis/flag-icons/issues/1236
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):
@NotTsunami commented on GitHub (May 9, 2024):
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.
@lipis commented on GitHub (May 21, 2024):
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..