javascript rotate image canvas
function drawRotated(degrees){
context.clearRect(0,0,canvas.width,canvas.height);
context.save();
context.translate(canvas.width/2,canvas.height/2);
context.rotate(degrees*Math.PI/180);
context.drawImage(image,-image.width/2,-image.width/2);
context.restore();
}