ImageOptim icon indicating copy to clipboard operation
ImageOptim copied to clipboard

viewBox stripped from SVG images

Open freshyill opened this issue 5 years ago • 6 comments

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 avatar Jul 14 '19 05:07 freshyill

@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

colourgarden avatar Sep 23 '19 14:09 colourgarden

Perhaps svgcleaner does this too?

kornelski avatar Sep 23 '19 14:09 kornelski

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.

colourgarden avatar Sep 23 '19 16:09 colourgarden

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.

RobbieTheWagner avatar Aug 14 '20 13:08 RobbieTheWagner

As of 1.8.8, with svgcleaner enabled, Imageoptim strips viewbox, ids, style elements (maybe others) from files even with lossy disabled.

swinggraphics avatar May 19 '21 22:05 swinggraphics

Would be super useful to have a setting for this or remove this behavior since putting viewBox in after optimization is a bit tedious. ;)

marijoo avatar Jul 23 '21 10:07 marijoo