glTF-Transform icon indicating copy to clipboard operation
glTF-Transform copied to clipboard

Expose more options for Squoosh-based compression

Open donmccurdy opened this issue 2 years ago • 1 comments

Options provided for the squoosh encoders are intentionally limited - i don't understand them all, and many are not documented by squoosh itself yet.:

https://github.com/donmccurdy/glTF-Transform/blob/6671e0c480ee990bfa119ea946e328bbe91f4233/packages/functions/src/squoosh.ts#L20-L24

But there are a few obvious ones we could easily add, like:

  • webp: 'quality' and 'lossless'
  • mozjpeg: 'quality'
  • oxipng: 'level', 'interlace'
    • web app exposes an 'effort' instead of 'level' and defaults to 'interlace=false' which i don't see in the codec api...

donmccurdy avatar May 12 '22 15:05 donmccurdy

Hey @donmccurdy bumping this because I would be interested in quality (and level) options. In fact, as a temporary workaround I've made a working one-line modification (excluding checks) to L128 of squoosh.ts. Below is the change with an explanation.

Previous: await image.encode({ [options.codec]: options.auto ? 'auto' : {} }); Modified: await image.encode({ [options.codec]: options.auto ? 'auto' : { quality: options.quality } });

For webp and mozjpeg, quality defaults to 75 and ranges from 0 to 100. For oxipng, instead of quality the level option defaults to 2 and ranges from 1 to 6. Additionally, there is a lossless option for webp.

Below are convenience links highlighting squoosh options, however I've only tested quality and level.

KristianZ avatar Sep 16 '22 23:09 KristianZ

Thanks @KristianZ! If you'd like to add the parameters you need and some documentation, a PR would be totally welcome! I've skipped adding more squoosh parameters myself until I've had a chance to test them and document how they work.

donmccurdy avatar Oct 02 '22 21:10 donmccurdy

Unfortunately I've been having more problems with squoosh, which appears to be unmaintained upstream. I'm planning to replace it with sharp:

  • #752
  • #751

We can certainly expose some of sharp's compression options when that happens, but I'll close this issue about Squoosh options for now.

donmccurdy avatar Dec 21 '22 02:12 donmccurdy

Darn, I was too slow. Well nonetheless thanks for the update @donmccurdy!

KristianZ avatar Dec 21 '22 18:12 KristianZ