title: Fabricjs - Scale canvas background to 'contain' within the canvas boundaries
body: <p>I'm trying to set the background image of a square fabric.js canvas so that it will fill the canvas on the longer side, while keeping the aspect ration, simulating the <code>background-size : 'contain'</code> effect on css.</p>
  
  <p>Meaning if image is portrait, the height should fill the screen while still keeping the aspect ratio. Otherwise, if the image is landscape, it should fill canvas on the width side while keeping the aspect ratio.</p>
  
  <p><a href="https://i.stack.imgur.com/jF9he.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jF9he.jpg" alt="enter image description here"></a></p>
  
  <p>I have this fiddle which scales and covers the canvas completely, somewhat similar to <code>'background-size' : 'cover'</code> on css.</p>
  
  <p><a href="https://jsfiddle.net/7s5obuk2/165/" rel="nofollow noreferrer">https://jsfiddle.net/7s5obuk2/165/</a></p>
  
  <p>But i havent been able to modify it successfully to achieve what i talked about above. Any help is appreciated.</p>