Broke image processing out into functions.