Home > Web Front-end > JS Tutorial > body text

js method to obtain the size of images uploaded locally by the front end

小云云
Release: 2017-12-13 15:22:50
Original
2332 people have browsed it

How to get the size of the image uploaded on the front end? This article will briefly share with you the js method to obtain the size of images uploaded locally by the front end. I hope it can help you.

var MyTest = document.getElementById("upload_img").
files[0];var reader = new FileReader();
reader.readAsDataURL(MyTest);
reader.onload = function(theFile)
 { 
  var image = new Image(); 
   image.src = theFile.target.result;  
     image.onload = function() 
     {   
       alert("图片的宽度为"+this.width+",长度为"+this.height);    };
};
Copy after login

Among them, the tag with the id "upload_img" is as follows:

<input type="file" size="20" autocomplete="off" id="upload_img" name="Uploadfile">
Copy after login

Everyone Have you learned it? Hurry up and give it a try.

Related recommendations:

How to change the size of an image using PHP_PHP tutorial

Detailed explanation of how to get the true size of an image using JavaScript

Share a JS method to obtain image size and preview

The above is the detailed content of js method to obtain the size of images uploaded locally by the front end. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!