fixed code to keep the aspect ratio of the required image