amos-tool
Version:
amos ui tool
35 lines (33 loc) • 1 kB
JavaScript
;
function imageCompress(e, t, n) {
n || (n = .92), function(e, t) {
var n = new FileReader;
n.onload = function() {
var e = this.result;
t(e);
}, n.readAsDataURL(e);
}(e, function(e) {
!function(e, t) {
var n = new Image;
n.onload = function() {
t(n);
}, n.src = e;
}(e, function(e) {
!function(e) {
var a = function(e) {
var t = document.createElement("canvas"), a = e.width, r = e.height;
t.width = a, t.height = r, t.getContext("2d").drawImage(e, 0, 0, a, r);
var o = t.toDataURL("image/jpeg", n);
return o;
}(e), r = function(e) {
for (var t, n = atob(e.split(",")[1]), a = new ArrayBuffer(n.length), r = new Uint8Array(a), o = 0; o < n.length; o++) r[o] = n.charCodeAt(o);
return t = new Blob([ a ], {
type: "image/jpeg"
}), t;
}(a);
t(r);
}(e);
});
});
}
module.exports = imageCompress;