Topic: how to get the height and width of the uploaded image using javascript

HI
  I want to put client validations to image before submit form.
so i want to get the height and width of the images into javascript
Am using

var img = document.getElementById('imageid');
//or however you get a handle to the IMG
var width = img.clientWidth;
var height = img.clientHeight;

but its showing wrong dimentions.


can anybody help

Re: how to get the height and width of the uploaded image using javascript

Is the image being rendered to the page before you try and calculate its size?

Re: how to get the height and width of the uploaded image using javascript

var imgObj = document.getElementById('uploadedImage');
var newImg = new Image();
newImg.src = imgObj.attr('src');
var height = newImg.height;
var width = newImg.width;
imgObj.style.width = width;
imgObj.style.height = height;

You can use this code on your java script to get height and width of image.I hope this will work.Good luck.


Dating advice for women

Re: how to get the height and width of the uploaded image using javascript

You can use a image web viewer application, first you need to load your image into the web viewer, and then you can check the upload image parameter, such as image height and width. besides, image windows viewer also can be a good solution.