remove write_to_image in encode_image()