qc-image-lrz
Version:
1 lines • 23 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("qc-image-lrz",[],t):"object"==typeof exports?exports["qc-image-lrz"]=t():e.QcImageLrz=t()}(window,function(){return o={},r.m=i={"../../node_modules/_exif-js@2.3.0@exif-js/exif.js":function(e,t,i){var l;(function(){var c=!1,a=function(e){return e instanceof a?e:this instanceof a?void(this.EXIFwrapped=e):new a(e)};e.exports&&(t=e.exports=a);var h=(t.EXIF=a).Tags={36864:"ExifVersion",40960:"FlashpixVersion",40961:"ColorSpace",40962:"PixelXDimension",40963:"PixelYDimension",37121:"ComponentsConfiguration",37122:"CompressedBitsPerPixel",37500:"MakerNote",37510:"UserComment",40964:"RelatedSoundFile",36867:"DateTimeOriginal",36868:"DateTimeDigitized",37520:"SubsecTime",37521:"SubsecTimeOriginal",37522:"SubsecTimeDigitized",33434:"ExposureTime",33437:"FNumber",34850:"ExposureProgram",34852:"SpectralSensitivity",34855:"ISOSpeedRatings",34856:"OECF",37377:"ShutterSpeedValue",37378:"ApertureValue",37379:"BrightnessValue",37380:"ExposureBias",37381:"MaxApertureValue",37382:"SubjectDistance",37383:"MeteringMode",37384:"LightSource",37385:"Flash",37396:"SubjectArea",37386:"FocalLength",41483:"FlashEnergy",41484:"SpatialFrequencyResponse",41486:"FocalPlaneXResolution",41487:"FocalPlaneYResolution",41488:"FocalPlaneResolutionUnit",41492:"SubjectLocation",41493:"ExposureIndex",41495:"SensingMethod",41728:"FileSource",41729:"SceneType",41730:"CFAPattern",41985:"CustomRendered",41986:"ExposureMode",41987:"WhiteBalance",41988:"DigitalZoomRation",41989:"FocalLengthIn35mmFilm",41990:"SceneCaptureType",41991:"GainControl",41992:"Contrast",41993:"Saturation",41994:"Sharpness",41995:"DeviceSettingDescription",41996:"SubjectDistanceRange",40965:"InteroperabilityIFDPointer",42016:"ImageUniqueID"},u=a.TiffTags={256:"ImageWidth",257:"ImageHeight",34665:"ExifIFDPointer",34853:"GPSInfoIFDPointer",40965:"InteroperabilityIFDPointer",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",274:"Orientation",277:"SamplesPerPixel",284:"PlanarConfiguration",530:"YCbCrSubSampling",531:"YCbCrPositioning",282:"XResolution",283:"YResolution",296:"ResolutionUnit",273:"StripOffsets",278:"RowsPerStrip",279:"StripByteCounts",513:"JPEGInterchangeFormat",514:"JPEGInterchangeFormatLength",301:"TransferFunction",318:"WhitePoint",319:"PrimaryChromaticities",529:"YCbCrCoefficients",532:"ReferenceBlackWhite",306:"DateTime",270:"ImageDescription",271:"Make",272:"Model",305:"Software",315:"Artist",33432:"Copyright"},g=a.GPSTags={0:"GPSVersionID",1:"GPSLatitudeRef",2:"GPSLatitude",3:"GPSLongitudeRef",4:"GPSLongitude",5:"GPSAltitudeRef",6:"GPSAltitude",7:"GPSTimeStamp",8:"GPSSatellites",9:"GPSStatus",10:"GPSMeasureMode",11:"GPSDOP",12:"GPSSpeedRef",13:"GPSSpeed",14:"GPSTrackRef",15:"GPSTrack",16:"GPSImgDirectionRef",17:"GPSImgDirection",18:"GPSMapDatum",19:"GPSDestLatitudeRef",20:"GPSDestLatitude",21:"GPSDestLongitudeRef",22:"GPSDestLongitude",23:"GPSDestBearingRef",24:"GPSDestBearing",25:"GPSDestDistanceRef",26:"GPSDestDistance",27:"GPSProcessingMethod",28:"GPSAreaInformation",29:"GPSDateStamp",30:"GPSDifferential"},f=a.IFD1Tags={256:"ImageWidth",257:"ImageHeight",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",273:"StripOffsets",274:"Orientation",277:"SamplesPerPixel",278:"RowsPerStrip",279:"StripByteCounts",282:"XResolution",283:"YResolution",284:"PlanarConfiguration",296:"ResolutionUnit",513:"JpegIFOffset",514:"JpegIFByteCount",529:"YCbCrCoefficients",530:"YCbCrSubSampling",531:"YCbCrPositioning",532:"ReferenceBlackWhite"},d=a.StringValues={ExposureProgram:{0:"Not defined",1:"Manual",2:"Normal program",3:"Aperture priority",4:"Shutter priority",5:"Creative program",6:"Action program",7:"Portrait mode",8:"Landscape mode"},MeteringMode:{0:"Unknown",1:"Average",2:"CenterWeightedAverage",3:"Spot",4:"MultiSpot",5:"Pattern",6:"Partial",255:"Other"},LightSource:{0:"Unknown",1:"Daylight",2:"Fluorescent",3:"Tungsten (incandescent light)",4:"Flash",9:"Fine weather",10:"Cloudy weather",11:"Shade",12:"Daylight fluorescent (D 5700 - 7100K)",13:"Day white fluorescent (N 4600 - 5400K)",14:"Cool white fluorescent (W 3900 - 4500K)",15:"White fluorescent (WW 3200 - 3700K)",17:"Standard light A",18:"Standard light B",19:"Standard light C",20:"D55",21:"D65",22:"D75",23:"D50",24:"ISO studio tungsten",255:"Other"},Flash:{0:"Flash did not fire",1:"Flash fired",5:"Strobe return light not detected",7:"Strobe return light detected",9:"Flash fired, compulsory flash mode",13:"Flash fired, compulsory flash mode, return light not detected",15:"Flash fired, compulsory flash mode, return light detected",16:"Flash did not fire, compulsory flash mode",24:"Flash did not fire, auto mode",25:"Flash fired, auto mode",29:"Flash fired, auto mode, return light not detected",31:"Flash fired, auto mode, return light detected",32:"No flash function",65:"Flash fired, red-eye reduction mode",69:"Flash fired, red-eye reduction mode, return light not detected",71:"Flash fired, red-eye reduction mode, return light detected",73:"Flash fired, compulsory flash mode, red-eye reduction mode",77:"Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",79:"Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",89:"Flash fired, auto mode, red-eye reduction mode",93:"Flash fired, auto mode, return light not detected, red-eye reduction mode",95:"Flash fired, auto mode, return light detected, red-eye reduction mode"},SensingMethod:{1:"Not defined",2:"One-chip color area sensor",3:"Two-chip color area sensor",4:"Three-chip color area sensor",5:"Color sequential area sensor",7:"Trilinear sensor",8:"Color sequential linear sensor"},SceneCaptureType:{0:"Standard",1:"Landscape",2:"Portrait",3:"Night scene"},SceneType:{1:"Directly photographed"},CustomRendered:{0:"Normal process",1:"Custom process"},WhiteBalance:{0:"Auto white balance",1:"Manual white balance"},GainControl:{0:"None",1:"Low gain up",2:"High gain up",3:"Low gain down",4:"High gain down"},Contrast:{0:"Normal",1:"Soft",2:"Hard"},Saturation:{0:"Normal",1:"Low saturation",2:"High saturation"},Sharpness:{0:"Normal",1:"Soft",2:"Hard"},SubjectDistanceRange:{0:"Unknown",1:"Macro",2:"Close view",3:"Distant view"},FileSource:{3:"DSC"},Components:{0:"",1:"Y",2:"Cb",3:"Cr",4:"R",5:"G",6:"B"}};function r(e){return!!e.exifdata}function i(r,o){function t(e){var t=s(e);r.exifdata=t||{};var i=function(e){var t=new DataView(e);c&&console.log("Got file of length "+e.byteLength);if(255!=t.getUint8(0)||216!=t.getUint8(1))return c&&console.log("Not a valid JPEG"),!1;var i=2,n=e.byteLength;for(;i<n;){if(l=i,56===(s=t).getUint8(l)&&66===s.getUint8(l+1)&&73===s.getUint8(l+2)&&77===s.getUint8(l+3)&&4===s.getUint8(l+4)&&4===s.getUint8(l+5)){var r=t.getUint8(i+7);r%2!=0&&(r+=1),0===r&&(r=4);var o=i+8+r,a=t.getUint16(i+6+r);return m(e,o,a)}i++}var s,l}(e);if(r.iptcdata=i||{},a.isXmpEnabled){var n=function(e){if(!("DOMParser"in self))return;var t=new DataView(e);c&&console.log("Got file of length "+e.byteLength);if(255!=t.getUint8(0)||216!=t.getUint8(1))return c&&console.log("Not a valid JPEG"),!1;var i=2,n=e.byteLength,r=new DOMParser;for(;i<n-4;){if("http"==S(t,i,4)){var o=i-1,a=t.getUint16(i-2)-1,s=S(t,o,a),l=s.indexOf("xmpmeta>")+8,h=(s=s.substring(s.indexOf("<x:xmpmeta"),l)).indexOf("x:xmpmeta")+10;return s=s.slice(0,h)+'xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tiff="http://ns.adobe.com/tiff/1.0/" xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus" xmlns:ext="http://www.gettyimages.com/xsltExtension/1.0" xmlns:exif="http://ns.adobe.com/exif/1.0/" xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#" xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/" xmlns:xapGImg="http://ns.adobe.com/xap/1.0/g/img/" xmlns:Iptc4xmpExt="http://iptc.org/std/Iptc4xmpExt/2008-02-29/" '+s.slice(h),v(r.parseFromString(s,"text/xml"))}i++}}(e);r.xmpdata=n||{}}o&&o.call(r)}if(r.src)if(/^data\:/i.test(r.src))t(function(e,t){t=t||e.match(/^data\:([^\;]+)\;base64,/im)[1]||"",e=e.replace(/^data\:([^\;]+)\;base64,/gim,"");for(var i=atob(e),n=i.length,r=new ArrayBuffer(n),o=new Uint8Array(r),a=0;a<n;a++)o[a]=i.charCodeAt(a);return r}(r.src));else if(/^blob\:/i.test(r.src)){(i=new FileReader).onload=function(e){t(e.target.result)},function(e,t){var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="blob",i.onload=function(e){200!=this.status&&0!==this.status||t(this.response)},i.send()}(r.src,function(e){i.readAsArrayBuffer(e)})}else{var e=new XMLHttpRequest;e.onload=function(){if(200!=this.status&&0!==this.status)throw"Could not load image";t(e.response),e=null},e.open("GET",r.src,!0),e.responseType="arraybuffer",e.send(null)}else if(self.FileReader&&(r instanceof self.Blob||r instanceof self.File)){var i;(i=new FileReader).onload=function(e){c&&console.log("Got file of length "+e.target.result.byteLength),t(e.target.result)},i.readAsArrayBuffer(r)}}function s(e){var t=new DataView(e);if(c&&console.log("Got file of length "+e.byteLength),255!=t.getUint8(0)||216!=t.getUint8(1))return c&&console.log("Not a valid JPEG"),!1;for(var i,n=2,r=e.byteLength;n<r;){if(255!=t.getUint8(n))return c&&console.log("Not a valid marker at offset "+n+", found: "+t.getUint8(n)),!1;if(i=t.getUint8(n+1),c&&console.log(i),225==i)return c&&console.log("Found 0xFFE1 marker"),o(t,n+4,t.getUint16(n+2));n+=2+t.getUint16(n+2)}}var p={120:"caption",110:"credit",25:"keywords",55:"dateCreated",80:"byline",85:"bylineTitle",122:"captionWriter",105:"headline",116:"copyright",15:"category"};function m(e,t,i){for(var n,r,o,a,s=new DataView(e),l={},h=t;h<t+i;)28===s.getUint8(h)&&2===s.getUint8(h+1)&&(a=s.getUint8(h+2))in p&&((o=s.getInt16(h+3))+5,r=p[a],n=S(s,h+5,o),l.hasOwnProperty(r)?l[r]instanceof Array?l[r].push(n):l[r]=[l[r],n]:l[r]=n),h++;return l}function w(e,t,i,n,r){var o,a,s,l=e.getUint16(i,!r),h={};for(s=0;s<l;s++)o=i+12*s+2,!(a=n[e.getUint16(o,!r)])&&c&&console.log("Unknown tag: "+e.getUint16(o,!r)),h[a]=y(e,o,t,i,r);return h}function y(e,t,i,n,r){var o,a,s,l,h,c,u=e.getUint16(t+2,!r),g=e.getUint32(t+4,!r),f=e.getUint32(t+8,!r)+i;switch(u){case 1:case 7:if(1==g)return e.getUint8(t+8,!r);for(o=4<g?f:t+8,a=[],l=0;l<g;l++)a[l]=e.getUint8(o+l);return a;case 2:return S(e,o=4<g?f:t+8,g-1);case 3:if(1==g)return e.getUint16(t+8,!r);for(o=2<g?f:t+8,a=[],l=0;l<g;l++)a[l]=e.getUint16(o+2*l,!r);return a;case 4:if(1==g)return e.getUint32(t+8,!r);for(a=[],l=0;l<g;l++)a[l]=e.getUint32(f+4*l,!r);return a;case 5:if(1==g)return h=e.getUint32(f,!r),c=e.getUint32(f+4,!r),(s=new Number(h/c)).numerator=h,s.denominator=c,s;for(a=[],l=0;l<g;l++)h=e.getUint32(f+8*l,!r),c=e.getUint32(f+4+8*l,!r),a[l]=new Number(h/c),a[l].numerator=h,a[l].denominator=c;return a;case 9:if(1==g)return e.getInt32(t+8,!r);for(a=[],l=0;l<g;l++)a[l]=e.getInt32(f+4*l,!r);return a;case 10:if(1==g)return e.getInt32(f,!r)/e.getInt32(f+4,!r);for(a=[],l=0;l<g;l++)a[l]=e.getInt32(f+8*l,!r)/e.getInt32(f+4+8*l,!r);return a}}function S(e,t,i){var r="";for(n=t;n<t+i;n++)r+=String.fromCharCode(e.getUint8(n));return r}function o(e,t){if("Exif"!=S(e,t,4))return c&&console.log("Not valid EXIF data! "+S(e,t,4)),!1;var i,n,r,o,a,s=t+6;if(18761==e.getUint16(s))i=!1;else{if(19789!=e.getUint16(s))return c&&console.log("Not valid TIFF data! (no 0x4949 or 0x4D4D)"),!1;i=!0}if(42!=e.getUint16(s+2,!i))return c&&console.log("Not valid TIFF data! (no 0x002A)"),!1;var l=e.getUint32(s+4,!i);if(l<8)return c&&console.log("Not valid TIFF data! (First offset less than 8)",e.getUint32(s+4,!i)),!1;if((n=w(e,s,s+l,u,i)).ExifIFDPointer)for(r in o=w(e,s,s+n.ExifIFDPointer,h,i)){switch(r){case"LightSource":case"Flash":case"MeteringMode":case"ExposureProgram":case"SensingMethod":case"SceneCaptureType":case"SceneType":case"CustomRendered":case"WhiteBalance":case"GainControl":case"Contrast":case"Saturation":case"Sharpness":case"SubjectDistanceRange":case"FileSource":o[r]=d[r][o[r]];break;case"ExifVersion":case"FlashpixVersion":o[r]=String.fromCharCode(o[r][0],o[r][1],o[r][2],o[r][3]);break;case"ComponentsConfiguration":o[r]=d.Components[o[r][0]]+d.Components[o[r][1]]+d.Components[o[r][2]]+d.Components[o[r][3]]}n[r]=o[r]}if(n.GPSInfoIFDPointer)for(r in a=w(e,s,s+n.GPSInfoIFDPointer,g,i)){switch(r){case"GPSVersionID":a[r]=a[r][0]+"."+a[r][1]+"."+a[r][2]+"."+a[r][3]}n[r]=a[r]}return n.thumbnail=function(e,t,i,n){var r=function(e,t,i){var n=e.getUint16(t,!i);return e.getUint32(t+2+12*n,!i)}(e,t+i,n);if(!r)return{};if(r>e.byteLength)return{};var o=w(e,t,t+r,f,n);if(o.Compression)switch(o.Compression){case 6:if(o.JpegIFOffset&&o.JpegIFByteCount){var a=t+o.JpegIFOffset,s=o.JpegIFByteCount;o.blob=new Blob([new Uint8Array(e.buffer,a,s)],{type:"image/jpeg"})}break;case 1:console.log("Thumbnail image format is TIFF, which is not implemented.");break;default:console.log("Unknown thumbnail image format '%s'",o.Compression)}else 2==o.PhotometricInterpretation&&console.log("Thumbnail image format is RGB, which is not implemented.");return o}(e,s,l,i),n}function b(e){var t={};if(1==e.nodeType){if(0<e.attributes.length){t["@attributes"]={};for(var i=0;i<e.attributes.length;i++){var n=e.attributes.item(i);t["@attributes"][n.nodeName]=n.nodeValue}}}else if(3==e.nodeType)return e.nodeValue;if(e.hasChildNodes())for(var r=0;r<e.childNodes.length;r++){var o=e.childNodes.item(r),a=o.nodeName;if(null==t[a])t[a]=b(o);else{if(null==t[a].push){var s=t[a];t[a]=[],t[a].push(s)}t[a].push(b(o))}}return t}function v(e){try{var t={};if(0<e.children.length)for(var i=0;i<e.children.length;i++){var n=e.children.item(i),r=n.attributes;for(var o in r){var a=r[o],s=a.nodeName,l=a.nodeValue;void 0!==s&&(t[s]=l)}var h=n.nodeName;if(void 0===t[h])t[h]=b(n);else{if(void 0===t[h].push){var c=t[h];t[h]=[],t[h].push(c)}t[h].push(b(n))}}else t=e.textContent;return t}catch(e){console.log(e.message)}}a.enableXmp=function(){a.isXmpEnabled=!0},a.disableXmp=function(){a.isXmpEnabled=!1},a.getData=function(e,t){return!((self.Image&&e instanceof self.Image||self.HTMLImageElement&&e instanceof self.HTMLImageElement)&&!e.complete)&&(r(e)?t&&t.call(e):i(e,t),!0)},a.getTag=function(e,t){if(r(e))return e.exifdata[t]},a.getIptcTag=function(e,t){if(r(e))return e.iptcdata[t]},a.getAllTags=function(e){if(!r(e))return{};var t,i=e.exifdata,n={};for(t in i)i.hasOwnProperty(t)&&(n[t]=i[t]);return n},a.getAllIptcTags=function(e){if(!r(e))return{};var t,i=e.iptcdata,n={};for(t in i)i.hasOwnProperty(t)&&(n[t]=i[t]);return n},a.pretty=function(e){if(!r(e))return"";var t,i=e.exifdata,n="";for(t in i)i.hasOwnProperty(t)&&("object"==typeof i[t]?i[t]instanceof Number?n+=t+" : "+i[t]+" ["+i[t].numerator+"/"+i[t].denominator+"]\r\n":n+=t+" : ["+i[t].length+" values]\r\n":n+=t+" : "+i[t]+"\r\n");return n},a.readFromBinaryFile=function(e){return s(e)},void 0===(l=function(){return a}.apply(t,[]))||(e.exports=l)}).call(this)},"./src/index.js":function(e,t,i){"use strict";i.r(t),i.d(t,"init",function(){return o}),i.d(t,"version",function(){return a});var n=i("../../node_modules/_exif-js@2.3.0@exif-js/exif.js"),c=i.n(n),u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(e,t){this.base64UrlReg=/^data:image\/(\w+);base64,/i,this.type=null,this.size=null,this.fileIsBase64=null,this.fileIsString=null,this.sourceNewImg=null,this.canvas=null,this.ctx=null,this.resize=null,this.orientation=null,this.tempConfig=null,this.defaultConfig={name:this.createImgName(),width:750,height:null,quality:.8,type:"image/jpeg",resultMode:"base64",dev:!1},this.config=t?Object.assign({},this.defaultConfig,t):this.defaultConfig,this.config.dev&&console.group("[QcImageLrz Tip]");var i=null;Object.defineProperty(this,"file",{get:function(){return i},set:function(e){(i=e)?(this.config.name=this.createImgName(e.type),this.fileIsString="string"==typeof e,this.fileIsBase64=this.base64UrlReg.test(e),this.fileIsString?(this.type=this.getFileStringType(e,this.fileIsBase64),this.fileIsBase64&&(this.size=this.getBase64Size(e))):(this.type=e.type,this.size=e.size),this.config.dev&&console.log("[QcImageLrz Tip]-文件发生更新,已更新相关数据")):(this.type=e,this.size=e,this.fileIsBase64=e,this.config.dev&&console.log("[QcImageLrz Tip]-文件清除,已清空相关数据"))}}),e&&(this.file=e)};function o(e,t){return new r(e,t)}r.prototype.compress=function(e,t){var n=this;if(e&&(this.file=e),!document.createElement("canvas").getContext)throw new Error("[QcImageLrz Error]-浏览器不支持canvas");if(!this.file)throw new Error("[QcImageLrz Error]-未发现可压缩的图片对象或base64Url,请检查是否定义了file");return t&&(this.tempConfig=Object.assign({},this.config,t),this.config.dev&&console.log("[QcImageLrz Tip]-发现单独配置,已更新相关配置")),new Promise(function(t,i){if(n.fileIsString)n.core(n.file).then(function(e){return t(e)}).catch(function(e){return i(e)});else{var e=new FileReader;e.onload=function(){n.core(this.result).then(function(e){return t(e)}).catch(function(e){return i(e)})},e.readAsDataURL(n.file)}})},r.prototype.core=function(t){if(t){var a,s=this,l=(this.tempConfig||this.config).type||this.type,e=new Image,h=document.createElement("canvas");return this.sourceNewImg=e,this.canvas=h,new Promise(function(r,o){e.onerror=function(){var e=new Error("[QcImageLrz Error]-加载图片文件失败");throw o(e),e},e.onload=function(){try{c.a.getData("object"===u(s.file)?s.file:e,function(){if(s.orientation=c.a.getTag(this,"Orientation"),s.resize=s.createResize(),h.width=s.resize.width,h.height=s.resize.height,s.ctx=h.getContext("2d"),"image/jpeg"===l){for(var e=s.ctx.getImageData(0,0,s.resize.width,s.resize.height),t=0;t<e.data.length;t+=4)0===e.data[t+3]&&(e.data[t]=255,e.data[t+1]=255,e.data[t+2]=255,e.data[t+3]=255);s.ctx.putImageData(e,0,0)}var i=s.createBase64();if(i.length<10){var n=new Error("[QcImageLrz Error]-生成base64Url失败");throw o(n),n}a=s.compressResultDeal(i),s.tempConfig&&(s.tempConfig=null),r(a)})}catch(e){console.log("压缩失败"),s.resize=s.createResize(),h.width=s.resize.width,h.height=s.resize.height,a=s.compressResultDeal(t),s.tempConfig&&(s.tempConfig=null),r(a)}},e.src=t})}},r.prototype.createResize=function(){var e=this.tempConfig||this.config,t=this.sourceNewImg,i={width:t.width,height:t.height};if(-1<"5678".indexOf(this.orientation)&&(i.width=t.height,i.height=t.width),i.width<e.width||i.height<e.height)return this.config.dev&&console.log("[QcImageLrz Tip]-原图尺寸小于设定,采用原图尺寸!"),i;var n=i.width/i.height;return e.width&&e.height?n>=e.width/e.height?i.width>e.width&&(i.width=e.width,i.height=Math.ceil(e.width/n)):i.height>e.height&&(i.height=e.height,i.width=Math.ceil(e.height*n)):e.width?e.width<i.width&&(i.width=e.width,i.height=Math.ceil(e.width/n)):e.height&&e.height<i.height&&(i.width=Math.ceil(e.height*n),i.height=e.height),this.config.dev&&console.log("[QcImageLrz Tip]-压缩尺寸计算成功!"),i},r.prototype.createBase64=function(){var e=this.tempConfig||this.config,t=this.sourceNewImg,i=this.orientation,n=this.resize,r=this.canvas,o=this.ctx,a=e.type||this.type;switch(i){case 3:o.rotate(180*Math.PI/180),o.drawImage(t,-n.width,-n.height,n.width,n.height);break;case 6:o.rotate(90*Math.PI/180),o.drawImage(t,0,-n.width,n.height,n.width);break;case 8:o.rotate(270*Math.PI/180),o.drawImage(t,-n.height,0,n.height,n.width);break;case 2:o.translate(n.width,0),o.scale(-1,1),o.drawImage(t,0,0,n.width,n.height);break;case 4:o.translate(n.width,0),o.scale(-1,1),o.rotate(180*Math.PI/180),o.drawImage(t,-n.width,-n.height,n.width,n.height);break;case 5:o.translate(n.width,0),o.scale(-1,1),o.rotate(90*Math.PI/180),o.drawImage(t,0,-n.width,n.height,n.width);break;case 7:o.translate(n.width,0),o.scale(-1,1),o.rotate(270*Math.PI/180),o.drawImage(t,-n.height,0,n.height,n.width);break;default:o.drawImage(t,0,0,n.width,n.height)}return r.toDataURL(a,e.quality)},r.prototype.compressResultDeal=function(e){var t,i=this.tempConfig||this.config,n=this.sourceNewImg,r=this.getBase64Size(e);if(r>this.size?(t=this.file,"base64"!==i.resultMode||this.fileIsBase64||(t=this.fileConverBase64(n,this.type)),"file"===i.resultMode&&this.fileIsBase64&&(t=this.base64ConverFile(this.file)),this.config.dev&&console.log("[QcImageLrz Tip]-图片压缩过大,返回原图!")):(t=e,"file"===i.resultMode&&(t=this.base64ConverFile(e)),this.config.dev&&console.log("[QcImageLrz Tip]-图片压缩成功,返回压缩结果!")),this.config.dev){var o={result:{width:this.resize.width,height:this.resize.height,size:(r/1024).toFixed(2)+"kb",type:i.type,mode:i.resultMode},source:{width:n.width,height:n.height,size:(this.size/1024).toFixed(2)+"kb",type:this.type,mode:this.fileIsBase64?"base64":this.fileIsString?"other":"file"}};console.table(o),console.groupEnd()}return t},r.prototype.fileConverBase64=function(e,t){if(e&&t){var i=document.createElement("canvas");return i.width=e.width,i.height=e.height,i.getContext("2d").drawImage(e,0,0,e.width,e.height),i.toDataURL(t,1)}},r.prototype.base64ConverFile=function(e,t){if(e){var i=this.tempConfig||this.config;t=t||i.name;for(var n=this.getFileStringType(e,!0),r=e.split(",")[1],o=atob(r),a=o.length,s=new Uint8Array(a);a--;)s[a]=o.charCodeAt(a);return new File([s],t,{type:n})}},r.prototype.getFileStringType=function(e,t){return e=e||this.file,(t=t||this.fileIsBase64)?/image\/[A-z]+/.exec(e)[0]:"image/"+/.[A-z]+$/.exec(e)[0].replace(".","")},r.prototype.getBase64Size=function(e){if(e){var t=e.replace(this.base64UrlReg,""),i=t.indexOf("=");-1!==i&&(t=t.substring(0,i));var n=t.length;return parseInt(n-n/8*2)}},r.prototype.createImgName=function(e){var t=(e||"jpg").replace("image/","").replace("jpeg","jpg");return"img_"+Number(Math.random().toString().substr(2)).toString(36)+"."+t};var a="0.0.2";t.default=r}},r.c=o,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(i,n,function(e){return t[e]}.bind(null,n));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s="./src/index.js");function r(e){if(o[e])return o[e].exports;var t=o[e]={i:e,l:!1,exports:{}};return i[e].call(t.exports,t,t.exports,r),t.l=!0,t.exports}var i,o});