I have a canvas
which I convert to a image like so,
var can = document.getElementById('canvas');
var ctx = can.getContext('2d');
var img = new Image();
img.src = can.toDataURL();
I need to rotate this image now? Is it possible?
I have a canvas
which I convert to a image like so,
var can = document.getElementById('canvas');
var ctx = can.getContext('2d');
var img = new Image();
img.src = can.toDataURL();
I need to rotate this image now? Is it possible?
You need to create a new canvas, rotate it's 2dDrawingContext, draw your image data to it, then set that as the source
var canvas = document.createElement('canvas');
var ctx2 = canvas.getContext('2d');
ctx2.rotate(Math.PI/2);
ctx2.putImageData(ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height), 0, 0);
From there you can then call ctx2.toDataURL()
and slap it in your image.