Last active
August 29, 2015 14:05
-
-
Save TobiasWooldridge/674b099fb3000446b1be to your computer and use it in GitHub Desktop.
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
function canvasToBlob(canvas) { | |
var imageBase64 = canvas.toDataURL(); | |
var imageBinaryString = atob(imageBase64.split(',')[1]); | |
var imageBinary = new Uint8Array(imageBinaryString.length); | |
for (var i = 0; i < imageBinaryString.length; i++) { | |
imageBinary[i] = imageBinaryString.charCodeAt(i); | |
} | |
return new Blob([new Uint8Array(imageBinary)], {type: 'image/png'}); | |
} | |
function canvasToLocalFile(canvas, filename) { | |
var link = document.createElement("a"); | |
link.href = canvas.toDataURL(); | |
link.download = filename; | |
link.click(); | |
} | |
function canvasToFacebook(canvas) { | |
FB.login(function(response) { | |
var accessToken = response.authResponse.accessToken; | |
var fd = new FormData(); | |
fd.append("source", canvasToBlob(canvas)); | |
fd.append("access_token", accessToken); | |
fd.append("message", "This is my university timetable, generated on http://unibuddy.com.au/"); | |
$.ajax({ | |
url:"https://graph.facebook.com/me/photos?access_token=" + accessToken, | |
type: "POST", | |
data: fd, | |
processData: false, | |
contentType: false, | |
cache: false | |
}); | |
}, {scope: 'user_photos,publish_actions,publish_stream'}); | |
} | |
function htmlToFacebook(node) { | |
html2canvas(node, { | |
onrendered: function(canvas) { | |
canvasToFacebook(canvas); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment