write out image
fix infinate try