more complex logic for resizing images to fit window