js获取上传图片真实的尺寸大小和存储大小
</pre><pre name="code" class="html"><input id="file" type="file"> <input id="Button1" type="button" value="button" onclick="check()"> <script> window.check=function(){ var input = document.getElementById("file"); if(input.files){ //读取图片数据 var f = input.files[0]; var reader = new FileReader(); reader.onload = function (e) { var data = e.target.result; //加载图片获取图片真实宽度和高度 var image = new Image(); image.onload=function(){ var width = image.width; var height = image.height; alert(width+"======"+height+"====="+f.size); }; image.src= data; }; reader.readAsDataURL(f); }else{ var image = new Image(); image.onload =function(){ var width = image.width; var height = image.height; var fileSize = image.fileSize; alert(width+"======"+height+"====="+fileSize); } image.src = input.value; } } </script>
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: HTML5 本地存储 localstorage 安全分析
- 下一篇: input标签获取图片文件尺寸