The javascript code is given below. It uses JQuery.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
$(document).ready(function() { imgSize(); } function imgSize() { var src = $('#myImage').attr('src'); var ow = $('#myImage').attr('width'); var oh = $('#myImage').attr('height'); var newImg = new Image(); newImg.src = src; var height = newImg.height; var width = newImg.width; p = $(newImg).ready(function(){ var nw = newImg.width; var nh = newImg.height; if (parseInt(nw) < parseInt(ow) ) $('#myImage').attr("width", ""); if (parseInt(nh) < parseInt(oh) ) $('#myImage').attr("height", ""); return {width: newImg.width, height: newImg.height}; }); The example IMG tag is shown below <img id="myImage" align = center src="myimages/demoimage.jpg" width="150" height="190"/> |



