I am using jQuery+AJAX to upload image and then generate html to show it. After successfully uploading the image, the AJAX gets the image filename. I want to get the image’s dimension ratio before actually loading it. Otherwise, if I load the image and use .width() and .height(), it will return 0 as it will take some time to load the image.
Is there any function in jQuery like getimagesize(filename) of PHP?
* edit *
Sorry for the confusion! I want a function in js not in PHP, and the function is like getimagesize(filename) of PHP.
* edit again *
I post the simplified code here:
var html = '<img id="photo' + id + '" src="' + filename + '" />';
$('#photos li:last').html(html);
var e = $('#photo' + id);
(e.width() / e.height() > 1.6) ? e.attr('width', 160): e.attr('height', 100);
Problem here is .width() and .height() are both 0. if using clientWidth and clientHeight, they are undefined.
1 Answer