mxismean / image-tiny Goto Github PK
View Code? Open in Web Editor NEWNPM 插件:图片压缩(浏览器端本地压缩),支持 png、jpg、gif 格式的图片压缩
License: MIT License
NPM 插件:图片压缩(浏览器端本地压缩),支持 png、jpg、gif 格式的图片压缩
License: MIT License
报如下错误
Module.instantiateWasm callback failed with error: ReferenceError: fetch is not defined
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(n="undefined"!=typeof globalThis?globalThis:n||self)["image-tiny"]=e()}(this,(function(){"use strict";function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},n(e)}var e,t={};t.instantiateWasm=function(n,e){fetch("pngtiny-custom.wasm").then((function(n){return n.arrayBuffer()})).then((function(e){return WebAssembly.instantiate(e,n)})).then((function(n){return e(n.instance)}))},e||(e=void 0!==t?t:{});var r,i,o,a,u,s,f=Object.assign({},e),c="./this.program",l=function(n,e){throw e},p="object"==("undefined"==typeof window?"undefined":n(window)),m="function"==typeof importScripts,d="";"object"==("undefined"==typeof process?"undefined":n(process))&&"object"==n(process.versions)&&"string"==typeof process.versions.node?(d=m?require("path").dirname(d)+"/":__dirname+"/",s=function(){u||(a=require("fs"),u=require("path"))},r=function(n,e){return s(),n=u.normalize(n),a.readFileSync(n,e?void 0:"utf8")},o=function(n){return(n=r(n,!0)).buffer||(n=new Uint8Array(n)),n},i=function(n,e,t){s(),n=u.normalize(n),a.readFile(n,(function(n,r){n?t(n):e(r.buffer)}))},1<process.argv.length&&(c=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2),"undefined"!=typeof module&&(module.exports=e),process.on("uncaughtException",(function(n){if(!(n instanceof en))throw n})),process.on("unhandledRejection",(function(n){throw n})),l=function(n,e){if(w||0<I)throw process.exitCode=n,e;e instanceof en||h("exiting due to exception: "+e),process.exit(n)},e.inspect=function(){return"[Emscripten Module object]"}):(p||m)&&(m?d=self.location.href:"undefined"!=typeof document&&document.currentScript&&(d=document.currentScript.src),d=0!==d.indexOf("blob:")?d.substr(0,d.replace(/[?#].*/,"").lastIndexOf("/")+1):"",r=function(n){var e=new XMLHttpRequest;return e.open("GET",n,!1),e.send(null),e.responseText},m&&(o=function(n){var e=new XMLHttpRequest;return e.open("GET",n,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),i=function(n,e,t){var r=new XMLHttpRequest;r.open("GET",n,!0),r.responseType="arraybuffer",r.onload=function(){200==r.status||0==r.status&&r.response?e(r.response):t()},r.onerror=t,r.send(null)});var y=e.print||console.log.bind(console),h=e.printErr||console.warn.bind(console);Object.assign(e,f),f=null,e.thisProgram&&(c=e.thisProgram),e.quit&&(l=e.quit);var v,_=0;e.wasmBinary&&(v=e.wasmBinary);var w=e.noExitRuntime||!0;"object"!=("undefined"==typeof WebAssembly?"undefined":n(WebAssembly))&&q("no native wasm support detected");var g,b,A,R,S,E=!1,x="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function T(n,e,t){var r=e+t;for(t=e;n[t]&&!(t>=r);)++t;if(16<t-e&&n.subarray&&x)return x.decode(n.subarray(e,t));for(r="";e<t;){var i=n[e++];if(128&i){var o=63&n[e++];if(192==(224&i))r+=String.fromCharCode((31&i)<<6|o);else{var a=63&n[e++];65536>(i=224==(240&i)?(15&i)<<12|o<<6|a:(7&i)<<18|o<<12|a<<6|63&n[e++])?r+=String.fromCharCode(i):(i-=65536,r+=String.fromCharCode(55296|i>>10,56320|1023&i))}}else r+=String.fromCharCode(i)}return r}function j(n){return n?T(R,n,void 0):""}function k(){var n=g.buffer;b=n,e.HEAP8=A=new Int8Array(n),e.HEAP16=new Int16Array(n),e.HEAP32=S=new Int32Array(n),e.HEAPU8=R=new Uint8Array(n),e.HEAPU16=new Uint16Array(n),e.HEAPU32=new Uint32Array(n),e.HEAPF32=new Float32Array(n),e.HEAPF64=new Float64Array(n)}"undefined"!=typeof TextDecoder&&new TextDecoder("utf-16le");var P,U=[],H=[],W=[],I=0;function C(){var n=e.preRun.shift();U.unshift(n)}var F,M=0,D=null;function q(n){throw e.onAbort&&e.onAbort(n),h(n="Aborted("+n+")"),E=!0,new WebAssembly.RuntimeError(n+". Build with -s ASSERTIONS=1 for more info.")}function B(){return F.startsWith("data:application/octet-stream;base64,")}if(e.preloadedImages={},e.preloadedAudios={},F="pngtiny.wasm",!B()){var z=F;F=e.locateFile?e.locateFile(z,d):d+z}function L(){var n=F;try{if(n==F&&v)return new Uint8Array(v);if(o)return o(n);throw"both async and sync fetching of the wasm failed"}catch(n){q(n)}}function O(n){for(;0<n.length;){var t=n.shift();if("function"==typeof t)t(e);else{var r=t.h;"number"==typeof r?void 0===t.g?N(r)():N(r)(t.g):r(void 0===t.g?null:t.g)}}}var G=[];function N(n){var e=G[n];return e||(n>=G.length&&(G.length=n+1),G[n]=e=P.get(n)),e}var X={};function J(){if(!K){var e,t={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==("undefined"==typeof navigator?"undefined":n(navigator))&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:c||"./this.program"};for(e in X)void 0===X[e]?delete t[e]:t[e]=X[e];var r=[];for(e in t)r.push(e+"="+t[e]);K=r}return K}var K,Q=[null,[],[]],V={__assert_fail:function(n,e,t,r){q("Assertion failed: "+j(n)+", at: "+[e?j(e):"unknown filename",t,r?j(r):"unknown function"])},_emscripten_throw_longjmp:function(){throw 1/0},abort:function(){q("")},emscripten_memcpy_big:function(n,e,t){R.copyWithin(n,e,e+t)},emscripten_resize_heap:function(n){var e=R.length;if(1073741824<(n>>>=0))return!1;for(var t=1;4>=t;t*=2){var r=e*(1+.2/t);r=Math.min(r,n+100663296);var i=Math;r=Math.max(n,r),i=i.min.call(i,1073741824,r+(65536-r%65536)%65536);n:{try{g.grow(i-b.byteLength+65535>>>16),k();var o=1;break n}catch(n){}o=void 0}if(o)return!0}return!1},environ_get:function(n,e){var t=0;return J().forEach((function(r,i){var o=e+t;for(i=S[n+4*i>>2]=o,o=0;o<r.length;++o)A[i++>>0]=r.charCodeAt(o);A[i>>0]=0,t+=r.length+1})),0},environ_sizes_get:function(n,e){var t=J();S[n>>2]=t.length;var r=0;return t.forEach((function(n){r+=n.length+1})),S[e>>2]=r,0},exit:function(n){w||0<I||(e.onExit&&e.onExit(n),E=!0),l(n,new en(n))},fd_close:function(){return 0},fd_seek:function(){},fd_write:function(n,e,t,r){for(var i=0,o=0;o<t;o++){var a=S[e>>2],u=S[e+4>>2];e+=8;for(var s=0;s<u;s++){var f=R[a+s],c=Q[n];0===f||10===f?((1===n?y:h)(T(c,0)),c.length=0):c.push(f)}i+=u}return S[r>>2]=i,0},getTempRet0:function(){return _},invoke_iii:function(n,e,t){var r=$();try{return N(n)(e,t)}catch(n){if(nn(r),n!==n+0)throw n;Z(1,0)}},invoke_vii:function(n,e,t){var r=$();try{N(n)(e,t)}catch(n){if(nn(r),n!==n+0)throw n;Z(1,0)}},invoke_viiii:function(n,e,t,r,i){var o=$();try{N(n)(e,t,r,i)}catch(n){if(nn(o),n!==n+0)throw n;Z(1,0)}},setTempRet0:function(n){_=n}};!function(){function n(n){e.asm=n.exports,g=e.asm.memory,k(),P=e.asm.__indirect_function_table,H.unshift(e.asm.__wasm_call_ctors),M--,e.monitorRunDependencies&&e.monitorRunDependencies(M),0==M&&D&&(n=D,D=null,n())}function t(e){n(e.instance)}function r(n){return function(){if(!v&&(p||m)){if("function"==typeof fetch&&!F.startsWith("file://"))return fetch(F,{credentials:"same-origin"}).then((function(n){if(!n.ok)throw"failed to load wasm binary file at '"+F+"'";return n.arrayBuffer()})).catch((function(){return L()}));if(i)return new Promise((function(n,e){i(F,(function(e){n(new Uint8Array(e))}),e)}))}return Promise.resolve().then((function(){return L()}))}().then((function(n){return WebAssembly.instantiate(n,o)})).then((function(n){return n})).then(n,(function(n){h("failed to asynchronously prepare wasm: "+n),q(n)}))}var o={env:V,wasi_snapshot_preview1:V};if(M++,e.monitorRunDependencies&&e.monitorRunDependencies(M),e.instantiateWasm)try{return e.instantiateWasm(o,n)}catch(n){return h("Module.instantiateWasm callback failed with error: "+n),!1}v||"function"!=typeof WebAssembly.instantiateStreaming||B()||F.startsWith("file://")||"function"!=typeof fetch?r(t):fetch(F,{credentials:"same-origin"}).then((function(n){return WebAssembly.instantiateStreaming(n,o).then(t,(function(n){return h("wasm streaming compile failed: "+n),h("falling back to ArrayBuffer instantiation"),r(t)}))}))}(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.__wasm_call_ctors).apply(null,arguments)},e._tiny=function(){return(e._tiny=e.asm.tiny).apply(null,arguments)},e._malloc=function(){return(e._malloc=e.asm.malloc).apply(null,arguments)},e._free=function(){return(e._free=e.asm.free).apply(null,arguments)},e._saveSetjmp=function(){return(e._saveSetjmp=e.asm.saveSetjmp).apply(null,arguments)},e.___errno_location=function(){return(e.___errno_location=e.asm.__errno_location).apply(null,arguments)};var Y,Z=e._setThrew=function(){return(Z=e._setThrew=e.asm.setThrew).apply(null,arguments)},$=e.stackSave=function(){return($=e.stackSave=e.asm.stackSave).apply(null,arguments)},nn=e.stackRestore=function(){return(nn=e.stackRestore=e.asm.stackRestore).apply(null,arguments)};function en(n){this.name="ExitStatus",this.message="Program terminated with exit("+n+")",this.status=n}function tn(){function n(){if(!Y&&(Y=!0,e.calledRun=!0,!E)){if(O(H),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for("function"==typeof e.postRun&&(e.postRun=[e.postRun]);e.postRun.length;){var n=e.postRun.shift();W.unshift(n)}O(W)}}if(!(0<M)){if(e.preRun)for("function"==typeof e.preRun&&(e.preRun=[e.preRun]);e.preRun.length;)C();O(U),0<M||(e.setStatus?(e.setStatus("Running..."),setTimeout((function(){setTimeout((function(){e.setStatus("")}),1),n()}),1)):n())}}if(e.stackAlloc=function(){return(e.stackAlloc=e.asm.stackAlloc).apply(null,arguments)},e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.dynCall_jiji).apply(null,arguments)},D=function n(){Y||tn(),Y||(D=n)},e.run=tn,e.preInit)for("function"==typeof e.preInit&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();tn();return function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:80;return t.run(),new Promise((function(r,i){try{var o=new FileReader;o.readAsArrayBuffer(n),o.onload=function(i){var o=new Uint8Array(i.target.result),a=o.byteLength,u=t._malloc(a),s=t._malloc(4);t.HEAPU8.set(o,u),t._tiny(u,a,s,e);var f=new Int32Array(t.HEAPU8.buffer,s,1),c=f[0];f=new Uint8Array(t.HEAPU8.buffer,u,c);var l=new Blob([f],{type:n.type}),p=new File([l],n.name,{type:n.type});0===p.size&&(p=n),r(p),t._free(u),t._free(s)}}catch(n){i(n)}}))}}));
在网页端压缩1M以上的图片就挺卡的,是耗时旧一点,然后还会影响页面卡顿
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.