Move image scaling code to ImageUtils

Just some refactoring to make image scaling code more reusable.