title: How to Replace the Existing image with the new Image in canvas Using the Fabric.js
body: <p>I need to replace the existing image with the new image from file upload from the computer, I want to replace the image with a newly uploaded image.  <a href="https://jsfiddle.net/jeevanhr/gb4u85q4/19/" rel="nofollow noreferrer">Here is the code (JSFiddle)</a>.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var canvas = new fabric.Canvas('c');
  
  function addImage () {
      fabric.Image.fromURL('http://lorempixel.com/400/200', function (img) {
       img.set({ 'left': 50 });
        img.set({ 'top': 50 });
        img.scaleToWidth(100);
        img.scaleToHeight(100);
        canvas.add (img);
      });
  }
  
  addImage();</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>canvas {
      border:1px solid #000;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.6.2/fabric.min.js"&gt;&lt;/script&gt;
  &lt;canvas id="c" width="400" height="200"&gt;&lt;/canvas&gt;
  &lt;span&gt;&lt;input type="file" name="" id="span"&gt;&lt;/span&gt;</code></pre>
  </div>
  </div>
  </p>