JSFiddle - React, Tailwind, and code Playground

by Manish Singh

HTML

<span id="preview"></span>

<input type="file" id="file" />

JavaScript

var _URL = window.URL || window.webkitURL;
function displayPreview(files) {
    var img = new Image(),
        fileSize=Math.round(files.size / 1024);
    
    img.onload = function () {
            var width=this.width,
                height=this.height,
                imgsrc=this.src;  
      
        doSomething(fileSize,width,height,imgsrc); //call function
        
        };   
img.src = _URL.createObjectURL(files);
}

// Do what you want in this function
function doSomething(size,width,height,imgsrc)
{
     $('#preview').append('<img src="'+imgsrc+'">'); 
   alert("Size="+size);
   alert("Width="+width+" height="+height);
  
    
}

$("#file").change(function () {
    var file = this.files[0];

    displayPreview(file);


});