Move image extraction into main.