l2aelba
l2aelba

Reputation: 22167

Drag & Drop a image via jQuery to get image dimensions

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)?

Upvotes: 0

Views: 1315

Answers (2)

l2aelba
l2aelba

Reputation: 22167

Ok , I post like this to PHP

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

    if($size[0]===150 && $size[1]===150) {
       // done
    } else {
       // error
    }

Upvotes: 0

Maen
Maen

Reputation: 10698

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);

Upvotes: 1

Related Questions