How to get the natural dimensions of an image using JavaScript or jQuery?
P粉916553895
P粉916553895 2023-10-21 13:53:08

So far I have this code:

var img = document.getElementById('draggable');
var width = img.clientWidth;
var height = img.clientHeight;

However, this gets me the html attribute - css style. I want to get the dimensions of the actual image resource of the file.

I need this because after uploading the image, its width is set to 0px and I don't know why or where this happens. To prevent this, I want to get the actual dimensions and reset them. is it possible?

EDIT: Even when I try to get the naturalWidth, the result is 0. I added a picture. The strange thing is that this only happens when I upload a new file and after a refresh it works fine.

http://oi39.tinypic.com/3582xq9.jpg

P粉916553895
P粉916553895

reply all(2)
Popular topics
More>
Latest downloads
More>
web effects
Website source code
Website materials
Front end template
About us Disclaimer Sitemap
PHP Chinese website:Public welfare online PHP training,Help PHP learners grow quickly!