// imageCompressorWorker.js // Import Compressor.js self.importScripts('https://cdn.jsdelivr.net/npm/compressorjs@1.0.7/dist/compressor.min.js'); self.onmessage = function(event) { const file = event.data; // Compress the image using Compressor.js without resizing new Compressor(file, { quality: 0.6, // Compress to 60% quality success(result) { // Convert compressed Blob to base64 and send it back const reader = new FileReader(); reader.onload = function(e) { self.postMessage({ success: true, data: e.target.result }); }; reader.onerror = function(error) { self.postMessage({ success: false, error }); }; reader.readAsDataURL(result); // Convert result to base64 for preview }, error(err) { self.postMessage({ success: false, error: err.message }); } }); };