ImageOptim
ImageOptim copied to clipboard
viewBox stripped from SVG images
ImageOptim always removes the viewBox attribute from SVG images. It's necessary for predictable scaling in the browser. I can't think of a reason why I'd actually want to remove the viewBox attribute, especially as a default option. I don't think SVGO removes it by default. Can an option be added to keep it?
@freshyill Are you using ImageOptim with lossy optimisation enabled?
In the SVGO config, removeViewBox
is only enabled in lossy mode - https://github.com/ImageOptim/ImageOptim/blob/master/svgo/index.js#L49
Perhaps svgcleaner does this too?
From the documentation:
svgcleaner is strictly lossless by default. There are no destructive cleaning options enabled by default.
svgcleaner shouldn't change your file unless you tell it to
Not conclusive without further testing but probably safe to say that svgcleaner is not removing it by default.
This is a big gotcha. It should be disabled by default. When adding the ImageOptim plugin on Netlify this will troll you. Seems to be no way to configure the plugin either.
As of 1.8.8, with svgcleaner enabled, Imageoptim strips viewbox, ids, style elements (maybe others) from files even with lossy disabled.
Would be super useful to have a setting for this or remove this behavior since putting viewBox in after optimization is a bit tedious. ;)