Apologies if I did not understand Anders' original question. I thought he
literally meant changing metadata without causing the pixel data to be read or
written at all (not merely whether it could be done implicitly without separate
API commands to deal with pixel data).
Daniel's solution is a good one, but you should be aware of the caveat that an
ImageBuf represents only a single image within the file. If the file in
question was a MIP-map, this code would lose all but the full-res
representation. If the file in question contained multiple subimages (like a
multi-part exr, or a movie file), these 3 lines would end up stripping out all
but the first exr part or the first frame of the movie.
There's no 3-line solution for handling all subimages of a multi-subimage files
correctly; it necessarily requires a bunch of surrounding logic to handle
extracting or encoding multiple images in one file. But if you don't *have* to
spell it out in python, you can do it very easily on the command line as
oiiotool -a imagefile.exr -attrib MyAttribute "my value" -o newfile.exr
(the -a means "do the things to all subimages and MIP levels", and oiiotool
itself contains all the logic to do that right)
> On Aug 4, 2022, at 3:34 AM, Daniel Flehner Heen <[email protected]>
> wrote:
>
> Great!
>
> On Thu, Aug 4, 2022, 11:53 Anders Langlands <[email protected]
> <mailto:[email protected]>> wrote:
> Hi Daniel that looks like exactly what I’m after, thanks!
>
> On Thu, 4 Aug 2022 at 20:45, Daniel Flehner Heen <[email protected]
> <mailto:[email protected]>> wrote:
> Hi!
>
> I hope I didn't misunderstand your question, but this should work:
>
> import OpenImageIO as oiio
>
> buf = oiio.ImageBuf('/path/to/imagefile.exr')
> buf.specmod().attribute('MyAttribute', 'my value')
> buf.write('/path/to/modified/imagefile.exr')
>
> Please note:
> I'm not sure you can avoid writing the whole file even if you overwrite the
> original.
> However creating an ImageBuf this way doesn't read the pixel data until write
> time or manipulated through ImageBufAlgo for instance.
>
>
> On Thu, Aug 4, 2022 at 5:14 AM Anders Langlands <[email protected]
> <mailto:[email protected]>> wrote:
> I want to open an image file and just set a few attributes in the header,
> then save it again not touching the image data at all. What's the
> quickest/easiest way to do this in the python API?
>
> Cheers,
> Anders
> _______________________________________________
> Oiio-dev mailing list
> [email protected] <mailto:[email protected]>
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
>
>
>
> --
> -Daniel
> _______________________________________________
> Oiio-dev mailing list
> [email protected] <mailto:[email protected]>
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
> _______________________________________________
> Oiio-dev mailing list
> [email protected] <mailto:[email protected]>
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
> _______________________________________________
> Oiio-dev mailing list
> [email protected]
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
--
Larry Gritz
[email protected]
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org