/ Published in: JavaScript
Use this snippet to get the native image size of an image if it is resized with CSS or IMG attributes. Requires jQuery.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript"> $(document).ready(function(){ // your selector $('img').each(function(index){ var img = $(this); // create new image object var newImg = new Image(); // get the src attribute to get the image size newImg.src = img.attr('src'); // for demo purposes, used to display height and width values img.hover(function(){ $('#size').html("<b>Height:</b>" + newImg.height + "px, <b>Width:</b>" + newImg.width + "px"); }); }); }); </script> // HTML MARKUP <span id="size"> <b>Height:</b> 00px, <b>Width:</b> 00px </span>
URL: http://marioluevanos.com/playground/Native%20Image%20Size/