I'm creating web application that picks out a randomly chosen image from google, and displays it in the browser window every time it is refreshed. What I'm struggling with is that I want the browser window to resize automatically to exactly fit the image displayed.

I know how to resize a browser window, but I want it done dynamically. Can anyone help me with this?