shssoichiro / oxipng

Multithreaded PNG optimizer written in Rust
MIT License
2.83k stars 121 forks source link

Allow specifying a minimum threshold for writing optimized files #286

Open aaronfranke opened 4 years ago

aaronfranke commented 4 years ago

By default, oxipng will only decide to not write a file if the optimized file is equal to (or, presumably in theory, greater than) the size of the original file. Writing can be forced with --force so that files are always written, but there is currently no way to go in the other direction and specify a minimum compression ratio that must be met before writing.

The reason I want this feature is that, if a file can only be compressed by a few bytes, it's not worth doing so for files stored in Git, since the benefit is small and it comes with the downside of increasing the size of the Git repo. I'm only interested in files that can see a significant amount of compression (I've noticed some can be reduced to half the size, for example).

I would like to specify a minimum compression threshold, so that if a file was only able to be compressed by, for example, less than 1 percent, then oxipng would not save the compressed file, but if the file was compressed by ex: 2% then it would be saved.

TPS commented 2 months ago

Is it possible to denote this in different ways, e.g., %age (1%, as above) or just a straight # of bytes (512, 1K, &c)?

aaronfranke commented 2 months ago

@TPS Percentage would be ideal, or a ratio (so 0.01 for 1%).