I am pretty new to HTML5 and was wondering how I would go about adding 10 random Facebook friends profile image's using JavaScript to an HTML5 Canvas, I have searched all over the net and have yet to find a solution that works, below is an example that I have been playing about with, I have created a Facebook App with the required permissions and can get a list of friends and their profile images I just can not figure out how to add them to the HTML5 Canvas.
<script>
function loadImages(sources, callback) {
var images = {};
var loadedImages = 0;
var numImages = 0;
// get num of sources
for(var src in sources) {
numImages++;
}
for(var src in sources) {
images[src] = new Image();
images[src].onload = function() {
if(++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
window.onload = function(images) {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var sources = {
canvasbackground: "prof.jpg",
userpic1: "https://graph.facebook.com/1645410740/picture",
userpic2: "https://graph.facebook.com/100000557085310/picture"
};
loadImages(sources, function(images) {
context.drawImage(images.canvasbackground, 0, 0, 422, 464);
context.drawImage(images.userpic1, 33, 28, 70, 70);
context.drawImage(images.userpic2, 130, 28, 70, 70);
});
};
</script>
Any help would be greatly appreciated.