updated code to save images in portrait mode