title: Fit the background image to canvas size with Fabric js
body: <p>I am trying to stretch the background image so it can fit the canvas size. But its not working. </p>
  
  <p>I have followed this question and based on comment i have implemented the stretching code.</p>
  
  <p><a href="https://stackoverflow.com/questions/29005435/strech-the-background-image-to-canvas-size-with-fabric-js">Strech the background image to canvas size with Fabric.js</a><br>
  <a href="http://fabricjs.com/docs/fabric.Canvas.html#setBackgroundImage" rel="noreferrer">http://fabricjs.com/docs/fabric.Canvas.html#setBackgroundImage</a></p>
  
  <h1>Code</h1>
  
  <pre><code>$(function () {     
      var canvas1 = new fabric.Canvas('canvas1');
              //Default
      var canvas = canvas1;
  
      //Change background using Image
      document.getElementById('bg_image').addEventListener('change', function (e) {
          canvas.setBackgroundColor('', canvas.renderAll.bind(canvas));
          canvas.setBackgroundImage(0, canvas.renderAll.bind(canvas));
          var file = e.target.files[0];
          var reader = new FileReader();
          reader.onload = function (f) {
              var data = f.target.result;
              fabric.Image.fromURL(data, function (img) {
                  img.set({
                      width: canvas.getWidth(), 
                      height: canvas.getHeight(), 
                      originX: 'left', 
                      originY: 'top'
                  });
                  canvas.setBackgroundImage(img, canvas.renderAll.bind(canvas));
                  /*canvas.setBackgroundImage(img, canvas.renderAll.bind(canvas), {
                      width: canvas.getWidth(),
                      height: canvas.getHeight(),
                      originX: 'left',
                      originY: 'top',
                      crossOrigin: 'anonymous'
                  });*/
              });
          };
          reader.readAsDataURL(file);
      });
  });
  </code></pre>
  
  <p>It seems that it is not working with latest beta version, however its working with 1.7.19 version but not with 2.0.0-beta.7</p>
  
  <p>JSFiddle: 
  version 2.0.0-beta.7:  <a href="http://jsfiddle.net/dhavalsisodiya/8vLo882n/3" rel="noreferrer">http://jsfiddle.net/dhavalsisodiya/8vLo882n/3</a></p>
  
  <p>varsion 1.7.19: <a href="http://jsfiddle.net/dhavalsisodiya/8vLo882n/4/" rel="noreferrer">http://jsfiddle.net/dhavalsisodiya/8vLo882n/4/</a></p>