refactoring image cropping