importScripts('https://cdn.jsdelivr.net/npm/jimp@0.16.0/browser/lib/jimp.js'); self.addEventListener('message', function (e) { const { dataURL, importantKey } = e.data; // dataURL => dataURL Jimp.read(dataURL) .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 importantKey } self.postMessage(res) }) .catch(err => { res = { stts: false, data: err, importantKey } self.postMessage(res) }) }) .catch(err => { res = { stts: false, data: err, importantKey } self.postMessage(res) }) })