var MyImage = new Image(); var MyHeight; MyImage.src = FileNames[MyIndex]; if(MyImage.height>MyImage.width) { MyHeight = 300; } else { MyHeight = MyImage.height*300/MyImage.width; }