imgbot / Imgbot

An Azure Function solution to crawl through all of your image files in GitHub and losslessly compress them. This will make the file size go down, but leave the dimensions and quality untouched. Once it's done, ImgBot will open a pull request for you to review and merge. help@imgbot.net
https://imgbot.net/
MIT License
1.24k stars 272 forks source link

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

Closed RogueScholar closed 4 years ago

RogueScholar commented 4 years ago

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? :wink:) 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? :roll_eyes: ...

:grin:

Warmly, Peter

dabutvin commented 4 years ago

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[bot] commented 4 years ago

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.

dabutvin commented 4 years ago

bump

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

dabutvin commented 4 years ago

PR open to take care of this #624

dabutvin commented 4 years ago

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