handle image file write