img: Support writing 3d file to an existing FILE*