How to use compressorjs - 3 common examples

To help you get started, we’ve selected a few compressorjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nerdic-coder / block-photos / src / services / photos-service.ts View on Github external
const reader = new FileReader();

              reader.addEventListener('loadend', () => {
                // reader.result contains the contents of blob as a DataURL
                resolve(reader.result);
              });
              reader.readAsDataURL(result);
            },
            error(err) {
              console.error(err.message);
            }
          });
          console.debug(compressor);
          return;
        } else if (photoType === PhotoType.Viewer) {
          const compressor = new Compressor(itemValue, {
            quality: 0.6,
            maxWidth: 2560,
            mimeType,
            checkOrientation: false,
            success(result) {
              const reader = new FileReader();

              reader.addEventListener('loadend', () => {
                // reader.result contains the contents of blob as a DataURL
                resolve(reader.result);
              });
              reader.readAsDataURL(result);
            },
            error(err) {
              console.error(err.message);
            }
github xland / xiangxuema / src / renderer / components / mixins / img.js View on Github external
imgCompress(fullName, cb) {
            let data = fs.readFileSync(fullName);
            let file = new File([data], path.basename(fullName), { type: this.fileTypeMap[path.extname(fullName).substr(1)] });
            if (this.$root.imgWidth > 0 && this.$root.imgHight > 0) {
                new compressor(file, {
                    quality: 0.8,
                    success(result) {
                        fs.unlinkSync(fullName)
                        let fr = new FileReader();
                        fr.onload = () => {
                            if (fr.readyState == 2) {
                                var buffer = new Buffer.from(fr.result);
                                fs.writeFileSync(fullName, buffer);
                                cb();
                            }
                        };
                        fr.readAsArrayBuffer(result);
                    },
                    error(err) {
                        console.log(err.message);
                    },
github arturi / uppy-plugin-image-compressor / src / index.js View on Github external
return new Promise((resolve, reject) => {
      new Compressor(blob, Object.assign(
        {},
        this.opts,
        {
          success: (result) => {
            return resolve(result)
          },
          error: (err) => {
            return reject(err)
          }
        }
      ))
    })
  }

compressorjs

JavaScript image compressor.

MIT
Latest version published 2 years ago

Package Health Score

71 / 100
Full package analysis