function to reduce image to a maximum width