title: setTransform and Scale to fit Canvas for the given image
body: <p>I have an image on Canvas. 
  After rendering an image, I rotate the canvas to 90 degrees clockwise and then have to scale to fit the canvas. </p>
  
  <p><a href="https://stackoverflow.com/questions/23104582/scaling-an-image-to-fit-on-canvas">Scaling an image to fit on canvas</a>
  <a href="https://stackoverflow.com/questions/44076873/resize-image-and-rotate-canvas-90-degrees">Resize image and rotate canvas 90 degrees</a></p>
  
  <p>there is so many solutions available but unfortunately none of them worked for me yet </p>
  
  <p>This is what I have right now. </p>
  
  <pre><code>width = 300; // after rotation
                      height = 400; // after rotation
                      var scale = width / img.height; // how much to scale the image to fit
  
                      console.log(scale);
                      canvas.width = width;
                      canvas.height = height;
                      ctx.setTransform(
                           0, scale, // x axis down the screen
                          -scale, 0, // y axis across the screen from right to left
                          width,    // x origin is on the right side of the canvas
                          0         // y origin is at the top
                      );
                      ctx.drawImage(img, 0, 0);
                      ctx.setTransform(1, 0, 0, 1, 0, 0); // restore default
  </code></pre>
  
  <p>Currently, canvas is rotating fine but image is not fitting or scaling properly according to canvas width and height.
  Original image is large, I want to scale it to fit 300x400 on canvas. </p>
  
  <p>Original Image - 
  <a href="https://i.stack.imgur.com/SQmuv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SQmuv.jpg" alt="enter image description here"></a></p>
  
  <p>Actual result image looks like this which is not scaling full image - </p>
  
  <p><a href="https://i.stack.imgur.com/TTEWR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TTEWR.png" alt="enter image description here"></a></p>