Refactored photo processing code into a function.