Extract image handling from routes.