Factored out image crop and scale functions so they can be testable.