var Canvas = function(id){ this.el = document.getElementById(id); this.screen = this.el.getContext("2d"); } Canvas.prototype = { loadImage: function(url) { return new Promise(_.bind(function(resolve) { var img = new Image(), self = this; img.onload = function() { self.el.width = img.width; self.el.height = img.height; self.screen.drawImage(img,0,0); return _.debounce(resolve(img),100); }; img.src = url; // make sure the load event fires for cached images too if ( img.complete || img.complete === undefined ) { img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="; img.src = url; } }, this)); }, toBoxShadow: function(blur, zoom, filter) { var width = this.screen.canvas.clientWidth, height = this.screen.canvas.clientHeight, imgData = this.screen.getImageData(0,0,width,height); var pixelShadow = ''; var x=0, y=0, color = 0, vector = []; for (var i=0;i