-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the benefit of stripping viewBox? #1128
Comments
Just as any stripping—minimize number of bytes, increase informational density. |
According to your readme:
Removing viewBox definitely affects the rendering result, since scaling is then made almost impossible. The question is, why is it turned on by default? It isn't simple meta-data, it is critical viewport information. |
Why? It's removed only when |
Removing I encountered this issue when an upgrade to svgo broke rendering of some scaled inline SVGs on our website (hypothesis/h#5656). The SVGs in question had an outer <svg xmlns="http://www.w3.org/2000/svg" width="120" height="120" viewBox="0 0 120 120">
…
</svg> And were being rendered with a CSS class applied that scaled them down to a much smaller size (eg. 16px x 16px). |
@robertknight that's incorrect usage, nothing to do with SVGO. Of course if you rewrite |
Please excuse the stupid question, but can you explain what you mean by incorrect usage? My understanding is that FWIW the original SVG file was produced some time ago by a designer using Sketch. |
SVG is an image which may have properties like |
I have also encountered an issue with this in IE11 as described by someone else here: https://stackoverflow.com/questions/27970520/svg-with-width-height-doesnt-scale-on-ie9-10-11. When I add the I know we can enable/disable the related plugins to not strip |
Just ran into this with SVGO defaults. Seems crazy that by default you break SVG scaling using CSS.
|
The viewBox needs to be preserved for inline The fact that SVGO is so configurable is really awesome, but many apps like Image Shrinker use the default settings and don't offer options, ultimately breaking SVGs for anyone wanting to scale them inline. Please see this CodePen: https://codepen.io/dahdah/pen/YzyjRaw Please reconsider changing the default value of
The above example shows pretty clearly that this setting does indeed affect the rendering result, and is not in line with what the SVGO readme promises. |
@GreLI are you prepared to reconsider this? |
Please change this. I spent a couple hours today digging around to figure out what's going on. The current default is super annoying... |
Same for me, the most used case is scalable svgs that doesn't broke with css. |
The same issue... |
I used the --icon prop that set '1em' to height and width and keep the viewbox, if this can help someone... My package.json command line look like this : |
I also agree with you, viewBox is very important for the scaling specially for web developper. In previous versions of svgo, removeViewBox was false by default. You should reconsider setting this option to false by default. |
Given this discussion, I created a PR to remove this plugin from the list of default plugins. #1461 In the meantime, this is the const { extendDefaultPlugins } = require('svgo');
module.exports = {
multipass: true,
plugins: extendDefaultPlugins([
// viewBox is required to resize SVGs with CSS.
// @see https://github.com/svg/svgo/issues/1128
{
name: 'removeViewBox',
active: false,
},
]),
}; |
I've updated PR #1461 to fix a merge conflict. Now that module.exports = {
multipass: true,
plugins: [
{
name: 'preset-default',
params: {
overrides: {
// viewBox is required to resize SVGs with CSS.
// @see https://github.com/svg/svgo/issues/1128
removeViewBox: false,
},
},
},
],
}; |
I understand the issue, sometimes 'viewBox' is really valuable, but it's not a good idea to dictate disabling default optimization by minority of users. Most users are ok with it and they just don't write here, it's totally ok for them. Probably it's a good idea to disable the plugin in some super-safe preset. |
@GreLI You haven't answered my question though. I have a logo that I want to place on a page as an SVG. Here's a minimal example: https://codepen.io/MoritzLost/pen/wvxvbdV I've optimized the SVG with SVGO. The first test case is the default SVGO output, for the second one I've added the Have you ever put a logo in the form of an SVG on a web page? If so, was your client fine with the behaviour in the first example? This is a super simple usage, not a special niche use-case or edge-case. Please example to me what I'm missing here.
Are you really sure that SVGs, Scalable Vector Graphics, shouldn't be allowed to scale? |
@MoritzLost ignoring my answers and spamming “You haven't answered” wouldn't get you anywhere. Don't be lazy to think it through. Please, follow GitHub Community Code of Conduct. |
You aren't answering our queries properly and saying others to follow the Code of Conduct? |
Whoops, I think this is an upstream issue with the SVG specification. What do you think @GreLI, should we fork https://github.com/w3c/svgwg/ and rename it to NSVG (Not Scalable Vector Graphics) so we finally have a format that matches the goal you apparently have with (n)svgo? Here is a fork I made, I renamed everything to the newer, more fitting name: Also feel free to take a look at the latest commit I pushed, changing the behavior of the |
this is a 3.5 year old thread, everyone. i think your effort would be better spent making a fork of svgo and trying to popularize it than posting in here. posting snarky comments or trying to explain the situation 10 times isn't helping. |
For the sane developer, have your SVGO config ready, create a file that looks like:
To test, In the CLI run:
Customize this file to suite your needs. |
I thought to point out in the readme exactly this option |
Maybe you should read your own readme file then:
This has been my first issue filed ever on GitHub and boy.... does it keep giving. |
The README is hypocritical, I've pointed this out before but the owner would simply ignore those. |
@GreLI You haven't answered, though. I have asked some questions regarding your stance on this issue and some problems I'm seeing with it. You haven't answered a single one of those, but just repeated the same non sequitur about 'changing the rendering' you have used multiple times. I'm not too lazy to think it through. I have written multiple paragraphs to try to understand your reasoning, explain why I disagree and kindly where my reasoning is wrong. You're the one who is not willing to engage at all, instead resorting to short, intellectually dishonest replies. Pointing to the code of conduct because someone disagrees with you is laughable. Why is it so difficult for you to accept that you're wrong? |
he's doubling down instead of acknowledging it. |
I have nothing more to add but this was a much needed break after fiddling the first time with SVGs in a web-context coming from Latex. I tried every setting of |
Wasted a couple of minutes on this problem today wondering why the SVGs were scaled incorrectly. (on the other hand, it led me into this Battle Thread filled with Don Quixotes🍿) |
…ssue the height and width on the raw SVG file were both set to 24 (matching the viewbox definition). Surprisngly, the image was being cut off. I found that removing the height/width properties resolved the issue. Looking further into it, the viewport was being removed by svgo - see [this](svg/svgo#1128) extensively discussed issue. Since we are re-scaling the svg with CSS to 20x20, we do need to preserve the image viewbox. Applying the solution from [this](svg/svgo#1128 (comment)) comment
Ok. I commented in this thread back on Sep 10, 2021. And I have been 🍿 watching we "minority of users" complaining in this thread. It has been fun until this freaking issue kicks my ass again today. I was using SVGR to render SVG as React component and I found that the SVG file loses viewport attribute thus can't resize properly. voice in my head -> SVGO: "SURPRISE M...F...r!" And I have to add a stupid svgo.config.js with configs in #1128 (comment) thanks to @GreLI's |
Thanks, for ignorance and arrogance |
This looks like a community-maintained repository. Shouldn't this issue be put to vote? On one hand, disabling We could require the plugin to be always specified in config with |
* feat(Nav): New search map icon + page title * fix(icon-search-map): Remove fill, height + width * fix(IconSearchMap): Restore height/width and fix underlying viewbox issue the height and width on the raw SVG file were both set to 24 (matching the viewbox definition). Surprisngly, the image was being cut off. I found that removing the height/width properties resolved the issue. Looking further into it, the viewport was being removed by svgo - see [this](svg/svgo#1128) extensively discussed issue. Since we are re-scaling the svg with CSS to 20x20, we do need to preserve the image viewbox. Applying the solution from [this](svg/svgo#1128 (comment)) comment * fix(GarageIcon): correct size Going through all other icons to see which had a viewbox that matched the width + height and found only two: icon-garage and icon-up-right-arrow. icon-up-right-arrow had sizing explicitly set in CSS and was not affected. icon-garage defaulted to the leaflet default marker size of 12x12. This explicitly sets the iconSize to 21x25, matching what is specified in the SVG. I noticed that the width and height SVG properties are being removed as part of [svg-inline-loader](https://github.com/webpack-contrib/svg-inline-loader/tree/4bb5529fbdd847d7809067fe11840b48ee13dde4#removesvgtagattrs-boolean). I thought about turning off that behavior as part of this PR, but it seems like it could affect more icons and I'm not really sure if it is necessary * test(SearchMapIcon): Add rendering test * fix(SearchMapIcon): Adjust sizing/viewbox so not cut off
@ADTC It's not "community-maintained" in a sense that we could just "put" this issue to vote. The most "active" maintainer nowadays is @TrySound, who seemingly abandoned this repo a couple of months ago. Seems like @GreLI also has rights to merge a PR, but we know their position... We can't find out exactly who has admin access to this repo but there are two more @svg organization members (@rpominov and @deepsweet), both seem to not care about this repo anymore as well, otherwise a crazy person like @GreLI wouldn't have admin access to it anymore. I'm just waiting for the moment @GreLI snaps and unpublishes the package or publishes it with some russian propaganda (something similar happened with another package in the past), so more people will notice and work on a fork. So yeah, the only realistic option here is a fork, I'd love to work on one but don't even have time to set it up. |
I'm the original author as it says in the At the same time I can't just blindly merge PRs to the project with 15M NPM downloads per week, so I've tried to look for maintainers over the years. It's way more complicated than it seems to be, starting from the observation that there are no many candidates. In fact, there are none. One thing is to merge old and stalled for months PRs, and another is to develop it all further and push forward. The only realistic way to dramatically change this situation is to contribute and be ready to become a new maintainer. Talk to me. |
@deepsweet thank you so much for coming back to chime in! I guess the position of active maintainer is still open and unlikely to be filled any time soon. In the meanwhile though, do you mind helping us update the Readme? I'd like to start with my own PR #1731 which organizes the content to be more readable without adding anything new. There's a discussion in the same PR about how to inform users of quirks like this, which I think would be best resolved by adding a FAQ or Troubleshooting section in the Readme. I can add it to the same PR or open a new one. I think changes to the Readme are much safer to merge than changes to the code. The Readme will also reflect in the NPM repository site so it is worth updating with new and important information. |
Some libraries use SVGO for optimizing the SVG and I notice that stripping the viewBox is almost always used. However, I always disable stripping because it breaks proper scaling of the SVG. Unless I totally don't understand, what is the 'optimization' that stripping a viewBox provides?
The text was updated successfully, but these errors were encountered: