Skip to content
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

[Feature Request]: Configuration option for compression threshold to trigger PR #562

Closed
RogueScholar opened this issue Jan 10, 2020 · 5 comments

Comments

@RogueScholar
Copy link

First things first, thank you for creating and sharing a magnificent development tool, I'm severely chagrined to have waited to say that until I also wished to prevail on you for an expanded feature set; my mother raised me better than that.

Nevertheless, I was curious if you had ever entertained giving users the option to set an explicit threshold for aggregate file size reduction for a PR to be sent? Put more plainly, I'd love to be able to set a precise value of kibibytes/mebibytes or a fractional amount of the total repository size that ImgBot would have to meet or exceed in compressing the contents before issuing a pull request.

I encountered a scenario recently where a confluence of the efforts of ImgBot and Restyled.io led to a "Groundhog Day-esque" scenario of duplicated PRs. As best I could determine, Restyled.io took umbrage at ImgBot failing to leave a trailing new line in the SVG files it compressed (a mildly compelling argument, at least to me...we shouldn't behave like wild animals in the pursuit of bandwidth/storage optimization, right? 😉) Anyhow, after absent-mindedly nodding my assent and merging Restyled's PR, I barely had time to sneeze and find a facial tissue before sitting back down at my desk to see that ImgBot had already opened another PR for all of those SVG files, despite the compression achieved amounting to exactly one fewer line per file or <0.01%. *shaking his fist in the air at being kicked in the backside by his fondness for configuring systems to manage everything*

Now I'll beat you to the punch here and concur that the more effective, dignified and appropriate remedy is to grab a spanner and a torch and crank away on Restyled's innards such that it learns not to molest anymore SVG files. I'll be doing so promptly at the conclusion of this missive, to be sure, and perhaps I'll be pleasantly surprised by how self-evident the method is for doing so. All the same, Restyled is a lexical parser, you and I both know that having my hands up its skirt will be a thoroughly gruesome affair compared to doing the same with an algorithmic sorceress of graphics like ImgBot. *sighs* That's Life by Sinatra just came on the radio, I guess that's curtains for me here.

Again, thank you for sharing ImgBot with me and I hope this late-night folly of a feature request wasn't too much torture to read. Keep on keepin' on; life's a garden, dig it? 🙄
...

😁

Warmly,
Peter

@dabutvin
Copy link
Contributor

Hi Peter 👋

This is a great idea! I am totally on board.
Here is some details of how I think it could be implemented, let me know what you think.

Right after we optimize the images we check to see what the total differential was
something like: var totalSaved = optimizedImages.Sum(x => x.SizeBefore - x.SizeAfter)

If there is a repo config setting set we compare and if it is not met then we bail out and do nothing.
something like: if (repoConfiguration.MinKBReduced > totalSaved) return false

How do you feel about the name "minKBReduced"?

// .imgbotconfig

{
  "minKBReduced": 25
}

It feels pretty spammy to send PRs for something less than 1 KB saved anyways, maybe we should set a default for this setting too?

Also we should update the docs along with this change:
https://github.com/dabutvin/Imgbot/blob/master/Docs/configuration.md
https://github.com/dabutvin/Imgbot/blob/master/README.md
https://github.com/dabutvin/Imgbot/blob/master/Docs/min-kb-reduced.md (new)

@stale
Copy link

stale bot commented Mar 11, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the goneStale label Mar 11, 2020
@dabutvin
Copy link
Contributor

bump

I've got a small start on this already and really want to get it in

@dabutvin
Copy link
Contributor

dabutvin commented Apr 6, 2020

PR open to take care of this #624

dabutvin added a commit that referenced this issue Apr 12, 2020
configuration option for compression threshold (fixes #562)
@dabutvin
Copy link
Contributor

This is now available to use in your repos with the .imgbotconfig file.

{
  "minKBReduced": 500
}

See https://imgbot.net/docs/#configuration

The default is set to 10KB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants