获取上传图片的宽高尺寸
2021-03-11 13:32
标签:reader his hang new asd style height dpi code 我们在上传图片时经常需要判断图片的尺寸是否在要求范围内 获取上传图片的宽高尺寸 标签:reader his hang new asd style height dpi code 原文地址:https://www.cnblogs.com/ybhome/p/12835598.html input type="file" onchange="loadPic(this)"/>
var Max_Size = 2000; //2M
var Max_Width = 100; //100px
var Max_Height = 200; //200px
function loadPic(file){
var fileData = file.files[0];
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
//加载图片获取图片真实宽度和高度
var image = new Image();
image.src= data;
image.onload=function(){
var width = image.width;
var height = image.height;
console.log(width,height)//图片真实宽高
};
};
reader.readAsDataURL(fileData);
}
上一篇:Web前端面试题目汇总
下一篇:CSS3圆角详解第一辑