function ImageAutoZoom(Img,FitWidth,FitHeight) { var image=new Image(); image.src=Img.src; if(image.width>0 && image.height>0) { if(image.width/image.height>= FitWidth/FitHeight) { Img.width=FitWidth; Img.height=(image.height*FitWidth)/image.width; } else { Img.height=FitHeight; Img.width=(image.width*FitHeight)/image.height; } } }