/*! * Image Compressor v1.1.3 * https://github.com/xkeshi/image-compressor * * Copyright (c) 2017-2018 Xkeshi * Released under the MIT license * * Date: 2018-03-23T01:35:12.857Z */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.ImageCompressor=t()}(this,function(){"use strict";var e,k=(function(e){var t,a,s,f,h,d,i;t=window,a=t.HTMLCanvasElement&&t.HTMLCanvasElement.prototype,s=t.Blob&&function(){try{return Boolean(new Blob)}catch(e){return!1}}(),f=s&&t.Uint8Array&&function(){try{return 100===new Blob([new Uint8Array(100)]).size}catch(e){return!1}}(),h=t.BlobBuilder||t.WebKitBlobBuilder||t.MozBlobBuilder||t.MSBlobBuilder,d=/^data:((.*?)(;charset=.*?)?)(;base64)?,/,i=(s||h)&&t.atob&&t.ArrayBuffer&&t.Uint8Array&&function(e){var t,r,n,a,i,o,l,u,c;if(!(t=e.match(d)))throw new Error("invalid data URI");for(r=t[2]?t[1]:"text/plain"+(t[3]||";charset=US-ASCII"),n=!!t[4],a=e.slice(t[0].length),i=n?atob(a):decodeURIComponent(a),o=new ArrayBuffer(i.length),l=new Uint8Array(o),u=0;uM.convertSize&&"image/png"===M.mimeType&&(v="#fff",M.mimeType="image/jpeg"),r.fillStyle=v,r.fillRect(0,0,u,c),r.save(),r.translate(u/2,c/2),r.rotate(p*Math.PI/180),r.scale(y,U),M.beforeDraw&&M.beforeDraw.call(x,r,e),r.drawImage(T,Math.floor(L(s)),Math.floor(L(f)),Math.floor(L(h)),Math.floor(L(d))),M.drew&&M.drew.call(x,r,e),r.restore();var b=function(e){t({naturalWidth:g,naturalHeight:w,result:e})};e.toBlob?e.toBlob(b,M.mimeType,M.quality):b(k(e.toDataURL(M.mimeType,M.quality)))})}).then(function(e){var t=e.naturalWidth,r=e.naturalHeight,n=e.result;if(d&&!M.checkOrientation&&d.revokeObjectURL(T.src),n)if(n.size>B.size&&M.mimeType===B.type&&!(M.width>t||M.height>r||M.minWidth>t||M.minHeight>r))n=B;else{var a=new Date;n.lastModified=a.getTime(),n.lastModifiedDate=a,n.name=B.name,n.name&&n.type!==B.type&&(n.name=n.name.replace(v,function(e){var t=!(1