img2enc: Make sure the images are atomically written