-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support squoosh #31
Comments
This looks like a cool idea! I expect that I would recommend keeping sharp as the default backend, but adding squoosh as an option and letting the end user choose which one to use. Then when the squoosh API hopefully one day becomes more stable, you can consider making it the default. But that's just my take, and I am not that familiar with this project :) |
@pi0 Usageconst fs = require('fs/promises');
const { ImagePool } = require('@squoosh/lib');
const { cpus } = require('os');
const imagePool = new ImagePool(cpus().length);
async function convert2WebpAndAvif(originalImage: Buffer) {
const image = imagePool.ingestImage(originalImage);
const encodeOptions = {
webp: {}, //empty object means using the default configuration
avif: {},
};
await image.encode(encodeOptions);
const [webp, avif] = await Promise.all([
image.encodedWith.webp,
image.encodedWith.avif,
]);
return {
webp,
avif,
};
}
// ==== Usage ==== //
const file = await fs.readFile('image.png');
const { webp, avif } = await convert2WebpAndAvif(imageBuffer);
await Promise.all([
fs.writeFile('image.webp', webp.binary),
fs.writeFile('image.avif', avif.binary),
]); Caveats and Concerns
|
The Squoosh library has unfortunately been discontinued indefinetely. You can still use the WASM enc/-decoders directly from the Squoosh source code, but other than that you are out of luck. Thankfully, you can instead use wasm-vips, which is a WASM implementation of the library that Sharp uses under the hood. In the future, we might even get a cross-platform version of sharp that uses wasm-vips. |
Closing this and waiting for wasm support for sharp. |
Do you have a link for that @atjn? Maybe you mean the "Project no longer maintained" notice on
Is this an ongoing project? Do you have a link for this @pi0 ? |
Sharp support for WASM seems ongoing here: lovell/sharp#3522 |
@karlhorky I am not entirely sure what you are asking for, but yes, the notice on @squoosh/lib is probably the most official communication available. I worked on @squoosh/lib, so I knew from talking to Jake that they were stopping work on it, and since it wasn't stable yet, that essentially killed the project for good. |
Seems like landed! Any plans to support it? |
@brendonmatos See #190 ;) |
squoosh is a wasm alternative to sharp. While sharp is much faster and supporting modern formats, it has its own downsides:
We can keep sharp as an opt-in dependency and install/use squoosh by default. This needs a refactor for handlers to create a shared interface. (as a result, we lose some existing features)
Note: squoosh api seems is not released on npm nor documented! We might use/redistribute http://npmjs.com/package/@squoosh/cli, inspire and inline source similar to vercel/next.js#22253, or publish as squoosh.
Related: GoogleChromeLabs/squoosh#934 / GoogleChromeLabs/squoosh#1002 (PR depends on NodeJS API like
worker_threads
therefore removing first point)The text was updated successfully, but these errors were encountered: