0

我使用jquery-filedrop并且我只允许用户上传文件 PNG & JPG

但是如何检查图像大小(如像素)?

可以在文件对象中获取图像大小吗?

在我查看了 console.log 中的文件对象之后,它与图像大小无关。

在此处输入图像描述

在此处输入图像描述

或者我必须检查 PHP 或附加图像所以.width()& .height() (REF)

4

2 回答 2

1

根据Georg Schölly回答

// 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);
于 2013-03-14T09:20:22.777 回答
0

好的,我这样发布到 PHP

$size = getimagesize($_FILES['name']['tmp_name']);

    if($size[0]===150 && $size[1]===150) {
       // done
    } else {
       // error
    }
于 2013-03-14T09:44:19.620 回答