importScripts('https://cdn.jsdelivr.net/npm/jimp@0.16.0/browser/lib/jimp.js');

self.addEventListener('message', function (e) {
  // e.data => dataURL
  Jimp.read(e.data)
    .then(image => {
      var width = image.bitmap.width
      if (width > 900) {
        width = 900
      }

      image
        .resize(width, Jimp.AUTO)
        .quality(60)
        .getBase64Async(Jimp.MIME_JPEG)
        .then((dataURL) => {
          res = {
            stts: true,
            data: dataURL // base64
          }
          self.postMessage(res)
        })
        .catch(err => {
          res = {
            stts: false,
            data: err
          }
          self.postMessage(res)
        })
    })
    .catch(err => {
      res = {
        stts: false,
        data: err
      }
      self.postMessage(res)
    })
})