image_optim icon indicating copy to clipboard operation
image_optim copied to clipboard

Add support for efficient-compression-tool

Open jwillikers opened this issue 7 months ago • 12 comments

Would it be possible to add support for efficient-compression-tool? I noticed I could get extra space savings when using this on a file already optimized with image_optim.

jwillikers avatar May 30 '25 21:05 jwillikers

At first look the tool is trying to improve compression, but the tools are already there, like zopfli is used by oxipng. Can you provide images for which you got better results? Maybe it is just about configuring present tools to apply maximum compression

toy avatar May 31 '25 12:05 toy

I've only see it further optimize PNG's. You can see it with this one. Running with ect -9 -strip I see a bit of space savings, albeit not much on top of what image_optim gets. It can even further optimize that image after running oxipng --interlace 0 --quiet --strip all -o max on it.

I think the author patches several of those dependencies, which might explain the difference.

jwillikers avatar May 31 '25 18:05 jwillikers

oxipng can be configured to do that by image_optim

toy avatar Jun 08 '25 14:06 toy

ect is impressive IMO. Recent benchmarks here - https://github.com/oxipng/oxipng/issues/700

Doing our own benchmarks might be useful, so we could remove some tools or disable them by default. I recently disabled advpng, optipng, and pngout because they don't seem worth it (for my use case).

Might also be useful to add command line flags to facilitate benchmarking. You can sorta get timing with --verbose but we could probably output a summary without too much trouble.

gurgeous avatar Aug 04 '25 04:08 gurgeous

@gurgeous There is script/worker_analysis for comparing all possible tool combinations and orders

toy avatar Aug 04 '25 21:08 toy

I tried running it, neat! After some experimentation I ended up changing my justfile rule to disable tools that seems slow and/or ineffective for my use case (see below). Based on my results I wonder if it's even worth including some of the tools at this point.

Would you be interested in more work here? It would be fun to contribute. Example - a script included in the gem similar to script/worker/analysis, but with fewer dependencies, no chaining, no yaml file required, a nice terminal summary, etc.

My justfile rule:

image-optim:
  @bundle exec image_optim \
    --no-optipng --no-pngout --no-advpng \
    --allow-lossy --svgo-precision=1 \
    -r .

gurgeous avatar Aug 05 '25 18:08 gurgeous

I tried running it, neat! After some experimentation I ended up changing my justfile rule to disable tools that seems slow and/or ineffective for my use case (see below). Based on my results I wonder if it's even worth including some of the tools at this point.

It always depends on input files, when understanding tools efficiency I created https://github.com/toy/image_optim_analysis with files that are used

Would you be interested in more work here? It would be fun to contribute. Example - a script included in the gem similar to script/worker/analysis, but with fewer dependencies, no chaining, no yaml file required, a nice terminal summary, etc.

Not sure I got what you mean by «no chaining». Overall you mean more of a tool for gem end users instead of developers to find what tools are efficient and which can be thrown our, or you mean adding it to main image_optim binary?

toy avatar Aug 05 '25 20:08 toy

There is also this - https://css-ig.net/benchmark/png-lossless which is somewhat unwieldy but contains many sample images for benchmarking. The author is showcasing his closed-source optimizer pingo, which I think is a variant of ect.

When I said "no chaining" I was referring to the worker_analysis script, which looks like it tries to chain the optimizers together (screenshot below). Maybe we could add something like image_optim --benchmark to compare the various optimizers and output a table. Or maybe --verbose could output a table at the end, showing results similar to worker_analysis.

Image

gurgeous avatar Aug 06 '25 01:08 gurgeous

So currently even without verbose image_optim outputs per image percentage and space gain + total, and verbose outputs duration of every worker. And you want to also add output per worker/tool, information like avg (median, total?) ratio, time, speed, …?

toy avatar Aug 09 '25 16:08 toy

Yes, I've run both with and without --verbose but I found it pretty challenging to understand the output and draw conclusions about which tools work best. This what I see with --verbose:

Image

But I want something like this:

$ image_optim --benchmark

Running image_optim on 37 pngs. Hang on...
Image

gurgeous avatar Aug 10 '25 23:08 gurgeous

The actual numbers in that screenshot are made up, of course. The output is from the Table Tennis rubygem that I released. We don't need to use that, I just put it in for fun and to show what's possible.

gurgeous avatar Aug 11 '25 16:08 gurgeous

@gurgeous Sure, it seems like it would be useful

Also probably better to further discuss if needed in a separate issue or discussions, or already in a PR, as this issue got hijacked

toy avatar Aug 17 '25 21:08 toy