HTML5 canvas translate back after scale and rotation

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<button id="rotate-right">Rotate right</button>
<button id="Rotate">Scale and Rotate</button><br>
<canvas id="canvas" ></canvas>

CSS

#canvas{border: 1px solid red;}

JavaScript

var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");

var degrees=0;
var orientation = 1;

var image=document.createElement("img");
var height, width, dimensions;
var scaledHeight, scaledWidth, scaleRatio;
image.onload=function(){
    canvas.width = image.width;
    canvas.height = image.height;    
    ctx.drawImage(image,0,0);
	
	height = image.height;
	width = image.width;
	dimensions = [height, width];
	dimensions.sort();
	
	var ratio = Math.min(480 / height, 640 / width);
	
}

//image.src="images/Left.JPG";
image.src="https://upload.wikimedia.org/wikipedia/commons/d/d5/Nyhavn%2C_Copenhagen.jpg";

//Normal rotate
//No scaling
 $("#rotate-right").click(function(){
     degrees+=90
     if (degrees >= 360) degrees = 0;
     
     if (degrees === 0 || degrees === 180 ) {
         canvas.width = image.width;
         canvas.height = image.height;
     }
     else {
         // swap
         canvas.width = image.height;
         canvas.height = image.width;
     }
  ctx.save();
  // you want to rotate around center of canvas
  ctx.translate(canvas.width/2,canvas.height/2);
    
  ctx.rotate(degrees*Math.PI/180);
  ctx.drawImage(image, -image.width*0.5, -image.height*0.5);
  ctx.restore();
});

//Rotate with Scaling
 $("#Rotate").click(function(){
    if (dimensions[0] > 480 || dimensions[1] > 853) {
		// Scale the image.
		var horizontal = width > height;
		if (horizontal) {
			scaledHeight = 480;
			scaleRatio = scaledHeight / height;
			scaledWidth = width * scaleRatio;
		} else {
			scaledWidth = 640;
			scaleRatio = scaledWidth / width;
			scaledHeight = height * scaleRatio;
		}
		
		canvas['width'] = scaledWidth;
		canvas['height'] = scaledHeight;
		ctx['drawImage'](image, 0, 0, width, height, 0, 0, scaledWidth, scaledHeight);
		/* Rotate Image */
		orientation = 6; //manual orientation -> on the site we use loadImage to get the orientation
		if(orientation != 1){
			switch(orientation){
				case 8:
				case 6:
					canvas.width =...