title: Javascript; Adding text on image using canvas and save to image
body: <p>i just want to make a page where u can type a text and add it on selected image and save that as new image.</p>
  
  <p>I tried to do it in few ways, but without luck. </p>
  
  <pre><code>&lt;body&gt;
  &lt;canvas id = "idCanvas" width = "576" height = "577"&gt; &lt;/canvas&gt;
  &lt;img id="canvasImg" width = "576" height = "577"&gt;&lt;/img&gt;
  &lt;script&gt;
  window.onload = function(){
    var canvas = document.getElementById('idCanvas');
    var context = canvas.getContext('2d');
    var imageObj = new Image();
    var dataURL = canvas.toDataURL();
  
    imageObj.onload = function() {
      context.drawImage(imageObj, 0, 0, 576, 577);
      context.font = "20px Calibri";
      context.fillText("My TEXT!", 50, 200);
  
      document.getElementById('canvasImg').src = toDataURL();
      window.alert(dataURL);
    };
    imageObj.src =  "image.png";
  
    };
  
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p></p>
  
  <p>When i use toDataURL() in img src, the image won't be displayed, it only works if i'm not using drawImage in canvas.</p>