JSFiddle - React, Tailwind, and code Playground

by Bnaya

HTML

<div style="">  
<br>
<span>בחר תמונה</span> <input type="file" class="picture-input" name="picture-input">
  <br>
</div>
<canvas id="canny" width="380" height="240"></canvas>
  <input type="text" class="name-input" value="ישראל ישראלי">
  <br>
  <a class="download-link" href="" download="meee.png">שמור תמונה</a>
  <img id="source" style="display: none;" alt=""...

CSS

body {
  direction: rtl;
  text-align: center;
}
#canny {
  display: block;
  margin: 0 auto;
  border: 1px solid #000;
  box-sizing: border-box;
}

.name-input {
  width: 200px;
}

JavaScript

$(function () {
  var ctx = $('#canny').get(0).getContext('2d');
  window.ctx = ctx;
    ctx.font = "16pt Arial";
  var profImage;
  
  if ($('#source').get(0).naturalWidth) {
      drawImage();
    drawText();
    drawProf();
  } else {
    $('#source').on('load', function () {
      drawImage();
    drawText();
    drawProf();
   
  });  
  }
    
  $('.name-input').on("keyup", function () {
    drawImage();
    drawText();
    drawProf();
  });

  $('.picture-input').on("change", function (e) {
    drawImage();
    drawText();
    imageProfileImageChange(e);

    drawProf();
  });
  
  function drawImage () {
    ctx.drawImage($('#source').get(0), -10, -50);
  }
  
  function drawText () {
    ctx.fillStyle = "green";
    ctx.fillText($('.name-input').val(), 330, 225);
  }
    
  function drawProf () {
    if (profImage) {
        ctx.drawImage(profImage, 266, 52, 103, 118);
    }
     updateDownload();
  }
  
  function imageProfileImageChange (e) {
          var file = e.target.files[0];
           imageType = /image.*/;

        if (!file.type.match(imageType))
            return;    
        var reader = new FileReader();
        reader.onload = fileOnload;
        reader.readAsDataURL(file);        
  }
  
  function fileOnload(e) {
    console.log('asd');
  var $img = $('<img>', { src: e.target.result });

    profImage = $img.get(0);
    
  $img.load(function() {
      drawProf();
  });
      
  }
  
      function updateDownload() {
      $('.download-link').attr('href', $('#canny').get(0).toDataURL('image/png'));
   }
});