JS Get picture width height and picture size

Source: Internet
Author: User

  

  

Get the IMG to view size

  varimg_url = ‘http://img5.imgtn.bdimg.com/it/u=4267222417,1017407570&fm=200&gp=0.jpg‘     // 创建img对象   var img = new Image();     // 改变图片的src   img.src = img_url;     // 加载完成执行   img.onload = function (){    // 打印    alert( ‘width:‘ +img.width+ ‘,height:‘ +img.height);That's it.
Get the size of the current picture  
<body> <br/> <input type= " File "onchange=" Selectimage (this); "/> <br/> <input type=" button "onclick=" Uploadimage (); " Value= "Submit"/> <script> var image = '; The value of function selectimage (file) { console.log (file.files)//output is as follows:
        
Console.log (file.files[0].size)//Get size
        The output is byte 1kb = 1024b so you want to convert the words will be parseint (file.files.size/1024)//Such a result is the KB if (!file.files | |!file. Files[0]) {return; } var reader = new FileReader (); Reader.onload = function (evt) {document.getElementById (' image '). src = evt.target.result; image = Evt.target.result; } reader.readasdataurl (File.files[0]); } function Uploadimage () {$.ajax ({type: ' POST ', url: ' admin.php ', Data: {image:image}, Async:false, DataType: ' JSON ', success:fun Ction (data) {Consoel.log (data) if (data.success) {alert (' upper Success '); } else {alert (' upload failed '); }}, Error:function (err) {Console.log (ERR) Alert (' Network Fault '); } }); } </script></body>

  

Know so much, there is no place to ask God to guide twos

JS Get picture width height and picture size

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.