Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery get image size

Tags:

jquery

image

size

I am creating a photo gallery using jquery. I am taking and resizing the images on load to create thumbnails. I want to get the original value of the image's size so that later on I can take it back to its original size. Anyone know how to do this? I have the following code:

    obj.find("img").each(function(){
}); 

This loops through all the images within the container div. I then tried to do:

$(this).width(); //didnt work
this.width; //didnt work

any ideas?

like image 833
ngreenwood6 Avatar asked Jan 10 '10 18:01

ngreenwood6


1 Answers

I asked the same question recently and got a good answer: A new image element is created but not attached to the DOM. Its height and width are the original dimensions of the image.

Edit: I edited the answer to my question now as promised in the comments. Detection of the image size is now bound to the onload event of the image to guarantee reliable results.

like image 163
Pekka Avatar answered Sep 19 '22 12:09

Pekka