Created
October 14, 2020 11:50
-
-
Save blackhalt/7c75a3273cd606ba4ec8cc4c2b7c8a7d to your computer and use it in GitHub Desktop.
glitch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){var t;t=function(){function t(){}return t.prototype.run=function(){return this.getImages(),this.buildCanvas(),this.process(),this.clean()},t.prototype.getImages=function(){return this.images=document.getElementsByTagName("img")},t.prototype.buildCanvas=function(){return this.canvas=document.createElement("canvas"),this.stage=this.canvas.getContext("2d"),document.body.appendChild(this.canvas),this.resizeCanvas(1,1)},t.prototype.resizeCanvas=function(t,e){return this.canvas.setAttribute("style","width: "+t+"px; height: "+e+"px; position: fixed; opacity: 0; left: -"+t+"px; top: -"+e+"px;"),this.canvas.setAttribute("width",t),this.canvas.setAttribute("height",e)},t.prototype.process=function(){var t,e,i,a,s,n;for(s=this.images,n=[],i=0,a=s.length;a>i;i++){e=s[i];try{this.image=e,this.allow(),this.setScale(),this.getImageData(),this.glitchData(),n.push(this.setData())}catch(r){t=r,n.push(console.log(t))}}return n},t.prototype.allow=function(){return this.image.setAttribute("crossOrigin","anonymous")},t.prototype.setScale=function(){var t,e;return e=this.image.offsetWidth,t=this.image.offsetHeight,this.resizeCanvas(e,t)},t.prototype.getImageData=function(){return this.stage.drawImage(this.image,0,0),this.data=this.canvas.toDataURL("image/jpeg")},t.prototype.glitchData=function(){var t,e,i,a,s;for(s=this.data.substring(0,this.data.indexOf(",")+1),e=this.data.substring(this.data.indexOf(",")+1),t=0,i=1+Math.floor(10*Math.random());i>t;)a=Math.round(Math.random()*e.length-1),e=e.substr(0,a)+e.charAt(a+1)+e.charAt(a)+e.substr(a+2),t++;return this.data=s+e},t.prototype.setData=function(){var t;return t=document.createElement("img"),t.setAttribute("width",this.image.offsetWidth),t.setAttribute("height",this.image.offsetHeight),t.setAttribute("src",this.data),document.body.insertBefore(t,this.image),this.image.parentNode.removeChild(this.image)},t.prototype.clean=function(){return this.canvas.parentNode.removeChild(this.canvas),this.image=null,this.data=null},t}(),window.glitch=new t,glitch.run()}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment