obtain image format and cleanup