我使用jquery-filedrop并且我允许用户仅上传文件PNG& JPG
但是如何检查图像尺寸(如像素)?
可以在文件对象中获取图像大小吗?
在我查看console.log中的文件对象后,它与图像大小无关。
或者我必须检查PHP或附加图像.width()
& .height()
(REF)?
答案 0 :(得分:1)
// find the element
var img = $('#imageid');
/*
* create an offscreen image that isn't scaled
* but contains the same image.
* Because it's cached it should be instantly here.
*/
var theImage = new Image();
theImage.src = img.attr("src");
// you should check here if the image has finished loading
// this can be done with theImage.complete
alert("Width: " + theImage.width);
alert("Height: " + theImage.height);
答案 1 :(得分:0)
好的,我这样发帖给PHP
$size = getimagesize($_FILES['name']['tmp_name']);
if($size[0]===150 && $size[1]===150) {
// done
} else {
// error
}