Note that there are some explanatory texts on larger screens.

plurals
  1. POJS - File Reader API get image file size and dimensions
    text
    copied!<p>Hi i'm using the following code to get the upload image using File Reader API:</p> <pre><code>&lt;script type="text/javascript"&gt; var loadImageFile = (function () { if (window.FileReader) { var oPreviewImg = null, oFReader = new window.FileReader(), rFilter = /^(?:image\/bmp|image\/cis\-cod|image\/gif|image\/ief|image\/jpeg|image\/jpeg|image\/jpeg|image\/pipeg|image\/png|image\/svg\+xml|image\/tiff|image\/x\-cmu\-raster|image\/x\-cmx|image\/x\-icon|image\/x\-portable\-anymap|image\/x\-portable\-bitmap|image\/x\-portable\-graymap|image\/x\-portable\-pixmap|image\/x\-rgb|image\/x\-xbitmap|image\/x\-xpixmap|image\/x\-xwindowdump)$/i; oFReader.onload = function (oFREvent) { /*get image*/ var _img = oFREvent.target.result; console.log(oFREvent.target); /*add img to hidden input text*/ localStorage.photo = _img; oPreviewImg.src = oFREvent.target.result; }; return function () { var aFiles = document.getElementById("imageInput").files; if (aFiles.length === 0) { return; } if (!rFilter.test(aFiles[0].type)) { notify("You must select a valid image file!",3400,false); return; } oFReader.readAsDataURL(aFiles[0]); } } })(); &lt;/script&gt; &lt;form name="uploadForm"&gt; &lt;p&gt;&lt;input id="imageInput" type="file" name="myPhoto" onchange="loadImageFile();" /&gt;&lt;br /&gt; &lt;input type="submit" value="Send" /&gt;&lt;/p&gt; &lt;input type="hidden" id="photo_1_hidden" name="photo_1"/&gt; &lt;/form&gt; </code></pre> <p>it works great and it returns the base64 data of the image.</p> <p>now i would like to get also the image file size and the image width and height.</p> <p>Is it possible?</p> <p>I tryed to log in console the file but i can't find what i'm searching for.</p> <p>Any help appriciated thanks so much!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload