Get Image Dimensions


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Get on screen image
  2. var screenImage = $("#image");
  3.  
  4. // Create new offscreen image to test
  5. var theImage = new Image();
  6. theImage.src = screenImage.attr("src");
  7.  
  8. // Get accurate measurements from that.
  9. var imageWidth = theImage.width;
  10. var imageHeight = theImage.height;

URL: http://css-tricks.com/snippets/jquery/get-an-images-native-width/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.