Created
August 18, 2012 04:34
-
-
Save mapmeld/3384452 to your computer and use it in GitHub Desktop.
GrabBlockee.js
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
// grab background: StreetView or uploaded | |
// 600 x 435 pixels | |
var bg = $('canvas')[1].parentNode.style.backgroundImage.substring(4); | |
bg = bg.substring(0, bg.length - 1); | |
var bgimage = new Image(); | |
bgimage.onload = function(){ | |
// grab image from foreground canvas | |
// 600 x 435 pixels to avoid menus | |
var uppercanv = $('canvas')[1].getContext('2d').getImageData(0, 0, 600, 435); | |
// paste background and foreground into a virtual canvas | |
var outcanv = document.createElement('canvas'); | |
outcanv.width = '600'; | |
outcanv.height = '435'; | |
var outcanvctx = outcanv.getContext('2d'); | |
try{ | |
outcanvctx.drawImage(bgimage, 0, 0); | |
} | |
catch(e){ | |
console.log("Can't drawImage using images from third-party servers"); | |
} | |
outcanvctx.putImageData(uppercanv, 0, 0); | |
// proof of concept | |
document.write('<img src="' + outcanv.toDataURL() + '"/>'); | |
}; | |
bgimage.src = bg; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment