image dimensions, client side after file upload selection
I have an upload form for an image. The user clicks browse and selects a file. How can I get the image dimensions the moment the user selects the file (before the file is even uploaded to the server). It obviously has to be something client-side with maybe javascript/jquery or flash/flex (prefer js//jquery though), but can either of them do 开发者_Python百科this?
This is the code I'm using to tie into zozo's getImgSize() function, but it gives me 0*0 as size. Any idea why?
$('#upload').change(function(){
if($(this).val() != null){
getImgSize(this);
}
});
The html is a normal input with on="getImgSize(this);"
function getImgSize(imgSrc)
{
var newImg = new Image();
newImg.src = imgSrc;
var height = newImg.height;
var width = newImg.width;
alert ('The image size is '+width+'*'+height);
}
精彩评论