Rotate Image 90 CW/CCW using Canvas

by pj_js15

HTML

<button id="rotate">Rotate with resize</button>
<p id=info></p>
<canvas id="canvas" width=400 height=400></canvas>

CSS

#canvas {
    border: 1px solid green;
}

JavaScript

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var imgWidth = 200;
var imgHeight = 300;
var size = {
    width: imgWidth,
    height: imgHeight
};
var rotation = 0;
var deg2Rad = Math.PI / 180;
var count1 = 0;
var count2 = 0;

var img = new Image();
img.onload = function () {
    imgWidth = img.width;
    imgHeight = img.height;
    size = {
        width: imgWidth,
        height: imgHeight
    };
    draw();
}
img.src =...