Hello my doubts today is how can I rotate a photo, say no to just turn rotate the photo in a browser but doing a photo that was taken in portrait and landscape stand in different angles to really change the picture, and all this with Jquery or JavaScript someone there to help?
JSFiddle: jsfiddle.net/6ZsCz/291
var look = false;
//**************************************************************************************
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var angleInDegrees = 0;
var image = document.createElement("img");
image.onload = function () {
ctx.drawImage(image, canvas.width / 2 - image.width / 2, canvas.height / 2 - image.width / 2);
}
image.src = "https://dl.dropboxusercontent.com/u/139992952/stackoverflow/house-icon.png";
//**************************************************************************************
var photoTwo = document.getElementById("photoTwo");
var ctxTwo = photoTwo.getContext("2d");
var angleInDegreesTwo = 0;
var imageTwo = document.createElement("img");
imageTwo.onload = function () {
ctxTwo.drawImage(imageTwo, photoTwo.width / 2 - imageTwo.width / 2, photoTwo.height / 2 - imageTwo.width / 2);
}
imageTwo.src = "https://dl.dropboxusercontent.com/u/139992952/stackoverflow/house-icon.png";
//**************************************************************************************
$("#clockwise").click(function () {
look = true;
angleInDegrees += 90;
drawRotated(angleInDegrees);
});
$("#counterclockwise").click(function () {
look = false;
angleInDegrees += 90;
drawRotated(angleInDegrees);
});
function drawRotated(degrees) {
var tmp_canvas;
var tmp_ctx;
var tmp_img;
if (look) {
tmp_canvas = canvas;
tmp_ctx = ctx;
tmp_img = image;
} else {
tmp_canvas = photoTwo;
tmp_ctx = ctxTwo;
tmp_img = imageTwo;
}
tmp_ctx.clearRect(0, 0, tmp_canvas.width, tmp_canvas.height);
tmp_ctx.save();
tmp_ctx.translate(tmp_canvas.width / 2, tmp_canvas.height / 2);
tmp_ctx.rotate(degrees * Math.PI / 180);
tmp_ctx.drawImage(tmp_img, -tmp_img.width / 2, -tmp_img.width / 2);
tmp_ctx.restore();
}