Initial commit
This commit is contained in:
38
public/assets/js/worker/jimp.js
vendored
Executable file
38
public/assets/js/worker/jimp.js
vendored
Executable file
@ -0,0 +1,38 @@
|
||||
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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user