Capture Image Attributes with Javascript or Jquery via Url

Asked

Viewed 81 times

1

I have an image that will be rendered in a Div, but I need to capture her Height because I need to treat it before putting it in the div (size). I don’t have the image on the screen, so I can’t do a Document.Getelement..

  • Take a look at this link, it might be useful, https://stackoverflow.com/questions/6575159/get-image-dimensions-with-javascript-before-image-has-fully-loaded

  • Oops! Thanks , it was very close that Guilherme posted here below.. and it worked! Thanks!

1 answer

1


Use the function below

var tmpImg = new Image();
tmpImg.src="https://www.google.com/intl/en_com/images/srpr/logo3w.png"; //or  document.images[i].src;
$(tmpImg).one('load',function(){
 orgWidth = tmpImg.width;
 orgHeight = tmpImg.height;
 alert(orgWidth+"x"+orgHeight);
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.