img-about
Version:
A module for image processing in browser, includes getting naturalSize, zooming, compressing... wrapped by Promise
10 lines (8 loc) • 1.64 kB
JavaScript
/**
* Bundle of img-about
* Generated: 2019-07-23
* Version: 2.2.0
* License: MIT
* Author: livelybone(2631541504@qq.com)
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).getNaturalSize=t()}(this,function(){"use strict";"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var e;t=e={exports:{}},n=function(){return function(e,t,n){t=t||"",n=n||512;for(var o=atob(e),r=[],i=0;i<o.length;i+=n){for(var a=o.slice(i,i+n),f=new Array(a.length),l=0;l<a.length;l++)f[l]=a.charCodeAt(l);var u=new Uint8Array(f);r.push(u)}return new Blob(r,{type:t})}},t.exports?(t.exports=n(),t.exports.default=t.exports):window.b64toBlob=n();var t,n;function o(r){return new Promise(function(e,t){var n=document.createElement("img"),o=function(){e({width:n.width,height:n.height})};n.onload=o,n.onerror=function(){t(new Error("Image<"+r+"> loaded error"))},n.src=r,n.complete&&o()})}document.createElement("canvas").getContext;return function(n){return new Promise(function(e,t){"string"==typeof n?e(o(n)):n instanceof Image?n.naturalWidth?e({width:n.naturalWidth,height:n.naturalHeight}):e(o(n.src)):n instanceof FileList||n instanceof File||n instanceof Blob?e(o(function(o){return new Promise(function(t,n){try{var e=new FileReader;e.onload=function(e){t(e.target.result)},e.readAsDataURL(o)}catch(e){n(e)}})}(n[0]||n))):t(new Error("The type of param `img` is not matched. It should be an instance of one of the String, Image, File, FileList and Blob"))})}});