0

I using jquery-filedrop and i allowed user to upload file only PNG & JPG

But how can I check image size (like pixel) ?

Possible to get image size in file object ?

After I looked at the file object in console.log , it's nothing about image size.

enter image description here

enter image description here

Or I have to check in PHP or append image so .width() & .height() (REF)?

Community
  • 1
  • 1
l2aelba
  • 21,591
  • 22
  • 102
  • 138

2 Answers2

1

According to this answer of 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);
Community
  • 1
  • 1
Maen
  • 10,603
  • 3
  • 45
  • 71
0

Ok , I post like this to PHP

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

    if($size[0]===150 && $size[1]===150) {
       // done
    } else {
       // error
    }
l2aelba
  • 21,591
  • 22
  • 102
  • 138