checking image size before upload

后端 未结 6 2020
暖寄归人
暖寄归人 2020-12-11 08:48

I noticed when uploading a profile pic to Twitter that its size is checked before upload. Can anyone point me to a solution like this?

Thanks

6条回答
  •  天命终不由人
    2020-12-11 09:48

    I have tested this code in chrome and it works fine.

    var x = document.getElementById('APP_LOGO'); // get the file input element in your form
    var f = x.files.item(0); // get only the first file from the list of files
    var filesize = f.size;
    alert("the size of the image is : "+filesize+" bytes");
    
    var i = new Image();
    var reader = new FileReader();
    reader.readAsDataURL(f);
    i.src=reader.result;
    var imageWidth = i.width;
    var imageHeight = i.height;
    alert("the width of the image is : "+imageWidth);
    alert("the height of the image is : "+imageHeight);
    

提交回复
热议问题