fengyuanchen / compressorjs

JavaScript image compressor.
https://fengyuanchen.github.io/compressorjs/
MIT License
5.23k stars 439 forks source link

Is there a way to synchronize? #152

Closed Gianna-w closed 2 years ago

fengyuanchen commented 2 years ago

What does "synchronize" mean exactly?

josuemoragl commented 2 years ago

Hi!, I guess Giana means to in order to ingress data return the compressed data with the same order. I have the same issue, I need to compare the two images, so I get to arrays, one for the original images and the other for the compressed images. When I show the comparison, the images order in both array are different.

fengyuanchen commented 2 years ago

You can use async/await and Promise for that:

async function compress(image) {
  return new Promise((resolve, reject) => {
    new Compressor(image, {
      success: resolve,
      error: reject,
    });
  }
}

async function process(images) {
  for (const image of images) {
    await compress(image);
  }
}

process(images);
josuemoragl commented 2 years ago

Thanks so much for your help Fengyuanchen