Skip to content
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

Closed
pi0 opened this issue May 18, 2021 · 10 comments
Closed

Support squoosh #31

pi0 opened this issue May 18, 2021 · 10 comments

Comments

@pi0
Copy link
Member

pi0 commented May 18, 2021

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)

@atjn
Copy link

atjn commented May 18, 2021

This looks like a cool idea! I expect that @squoosh/lib will be released on npm in a few days, but it will only be an experimental release. It has a list of known issues, it has spotty documentation, and the API isn't finalised yet.

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 :)

@EricSimons
Copy link

EricSimons commented May 28, 2021

Awesome to see this. Just want to add that enabling squoosh here will also enable full compatibility inside of WebContainers (more info in the blog post / repo)

@AbdallahAlhaddad
Copy link

@pi0
I have used @squoosh/lib": "^0.3.1 to optimize my backend images

Usage

const 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

  • When I used the latest version 0.4.0, avif format does not work, so I revert back to version 0.3.1.
  • The latest version (0.4.0) is 9 months old with no recent updates or bug fixes .
  • It needs nodejs v.16.* and doesn't work on the latest lts nodejs version (v18.*)
  • It takes a lot of time to convert images, which makes it unsuitable for converting images on demand (per API request), however, it can be used to process images in a work queue in the background and serve the optimized images when ready.

@atjn
Copy link

atjn commented Nov 20, 2022

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.

@pi0
Copy link
Member Author

pi0 commented Mar 31, 2023

Closing this and waiting for wasm support for sharp.

@pi0 pi0 closed this as completed Mar 31, 2023
@karlhorky
Copy link

karlhorky commented Mar 31, 2023

The Squoosh library has unfortunately been discontinued indefinetely

Do you have a link for that @atjn? Maybe you mean the "Project no longer maintained" notice on @squoosh/lib?

Project no longer maintained

Unfortunately, due to a few people leaving the team, and staffing issues resulting from the current economic climate (ugh), this package is no longer actively maintained. I know that sucks, but there simply isn't the time & people to work on this. If anyone from the community wants to fork it, you have my blessing. The squoosh.app web app will continue to be supported and improved.

Screenshot 2023-03-31 at 14 35 16

waiting for wasm support for sharp

Is this an ongoing project? Do you have a link for this @pi0 ?

@pi0
Copy link
Member Author

pi0 commented Mar 31, 2023

Sharp support for WASM seems ongoing here: lovell/sharp#3522

@atjn
Copy link

atjn commented Mar 31, 2023

@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.

@brendonmatos
Copy link

Seems like landed!
lovell/sharp#3522 (comment)

Any plans to support it?

@pi0
Copy link
Member Author

pi0 commented Dec 5, 2023

@brendonmatos See #190 ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants