-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path7-in.js
4 lines (4 loc) · 2.4 KB
/
7-in.js
1
2
3
4
//----------
//! glitch-canvas by snorpey - altered by Nathaniel Inman, MIT License
window.glitch=function(){function t(t,s,g){if(h(t)&&c(s,"parameters","object")&&c(g,"callback","function")){for(f=u(s),e(y,t),e(I,t),m=n(t,f.quality),p=i(m),l=r(p),v=0,k=f.iterations;k>v;v++)a(p,l,f.seed,f.amount,v,f.iterations);b=new Image,b.onload=function(){j.drawImage(b,0,0),w=j.getImageData(0,0,t.width,t.height),g(w)},b.src=o(p)}}function e(t,e){t.width!==e.width&&(t.width=e.width),t.height!==e.height&&(t.height=e.height)}function a(t,e,a,n,r,i){var o=t.length-e-4,u=parseInt(o/i*r,10),h=parseInt(o/i*(r+1),10),c=h-u,s=parseInt(u+c*a,10);s>o&&(s=o);var g=Math.floor(e+s);t[g]=Math.floor(256*n)}function n(t,e){var a="number"==typeof e&&1>e&&e>0?e:.1;E.putImageData(t,0,0);var n=I.toDataURL("image/jpeg",a);switch(n.length%4){case 3:n+="=";break;case 2:n+="==";break;case 1:n+="==="}return n}function r(t){var e=417;for(v=0,k=t.length;k>v;v++)if(255===t[v]&&218===t[v+1]){e=v+2;break}return e}function i(t){var e,a,n,r=[];for(v=23,k=t.length;k>v;v++){switch(a=x[t.charAt(v)],e=(v-23)%4){case 1:r.push(n<<2|a>>4);break;case 2:r.push((15&n)<<4|a>>2);break;case 3:r.push((3&n)<<6|a)}n=a}return r}function o(t){var e,a,n,r=["data:image/jpeg;base64,"];for(v=0,k=t.length;k>v;v++){switch(a=t[v],e=v%3){case 0:r.push(q[a>>2]);break;case 1:r.push(q[(3&n)<<4|a>>4]);break;case 2:r.push(q[(15&n)<<2|a>>6]),r.push(q[63&a])}n=a}return 0===e?(r.push(q[(3&n)<<4]),r.push("==")):1===e&&(r.push(q[(15&n)<<2]),r.push("=")),r.join("")}function u(t){return{seed:(t.seed||0)/100,quality:(t.quality||0)/100,amount:(t.amount||0)/100,iterations:t.iterations||0}}function h(t){return c(t,"image_data","object")&&c(t.width,"image_data.width","number")&&c(t.height,"image_data.height","number")&&c(t.data,"image_data.data","object")&&c(t.data.length,"image_data.data.length","number")&&s(t.data.length,"image_data.data.length",g,"> 0")?!0:!1}function c(t,e,a){return typeof t===a?!0:(d(t,"typeof "+e,'"'+a+'"','"'+typeof t+'"'),!1)}function s(t,e,a,n){return a(t)===!0?!0:void d(t,e,n,"not")}function g(t){return t>0}function d(t,e,a,n){throw new Error("glitch(): Expected "+e+" to be "+a+", but it was "+n+".")}var f,m,p,l,b,w,v,k,y=document.createElement("canvas"),I=document.createElement("canvas"),j=y.getContext("2d"),E=I.getContext("2d"),_="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",q=_.split(""),x={};return q.forEach(function(t,e){x[t]=e}),t}();
//----------