glTF-Transform
glTF-Transform copied to clipboard
Expose more options for Squoosh-based compression
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...
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.
- webp options
- mozjpeg options
- oxipng options (only level)
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.
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.
Darn, I was too slow. Well nonetheless thanks for the update @donmccurdy!