changed the process so that the image is resized only once