Fix aspect ratios of certain SVGs, also better data handling in general #121
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
By "certain SVGs", I mean ones without
widthorheightattributes and instead just doingviewBoxor something else. Previously, my SVGs (square) would always show up as 300x150 and would have extra transparent padding on the sides. This fixes that, so that the images would at least have the right aspect ratio, even if the dimensions aren't correct. The way I did this is to useHTMLImageElement.naturalWidthandnaturalHeight- letting the browser do all the complicated work with the standards. (this means that the SVG-to-PNG tool can technically resize other image types if the accepted file types are changed)"Better data handling" is using
blob:URLs instead ofdata:URLs everywhere possible, so we're not passing around massive strings with file contents, instead we're just using references toBlobs, and thoseBlobs hold the data outside of JavaScript. Additionally, there were someblob:URLs already being used (with SVG content) but not being freed withURL.revokeObjectURL, so I added someuseEffectcalls to clean those up.No visual changes, this is purely logic. Except for the results being the correct aspect ratio.
Please make sure you do the following before filing your PR:
pnpm run checkand make sure everything passes