hankknight
asked on
jQuery: Get Actual Width of Image
How can I get the ACTUAL width of an image, not the width of the image as it is displayed?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('img:eq(0)').attr('src', $('img:eq(0)').attr('src')).load(function () {
alert('The width of the image as it is displayed is: ' + $('img').width() );
alert('The actual width of the image is: ' + '???' );
// Should be 2272
})
});
</script>
<style type="text/css">
html, body, p, img {
width: 100%;
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<p>
<img src="http://upload.wikimedia.org/wikipedia/commons/7/7b/Pic-du-midi-dossau.jpg" alt="" />
</p>
</body>
</html>
sorry you want the real size image and not the resized/rendered one
2.272px × 1.704px
2.272px × 1.704px
ASKER
Does anybody else have a way to solve this using jQuery?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Great picture Gary - was over in France last week planning to climb this but the weather put a stop to it :(
Open in new window