Fix image file being left open