colour.io.write_image_OpenImageIO#

colour.io.write_image_OpenImageIO(image: ArrayLike, path: str | PathLike, bit_depth: Literal['uint8', 'uint16', 'float16', 'float32', 'float64', 'float128'] = 'float32', attributes: Sequence | None = None) bool[source]#

Write image data to the specified path using OpenImageIO.

Parameters:
  • image (ArrayLike) – Image data to write.

  • path (str | PathLike) – Path to the image file.

  • bit_depth (Literal['uint8', 'uint16', 'float16', 'float32', 'float64', 'float128']) – Bit-depth to write the image at. The bit-depth conversion behaviour is ruled directly by OpenImageIO.

  • attributes (Sequence | None) – An array of colour.io.Image_Specification_Attribute class instances used to set attributes of the image.

Returns:

Definition success.

Return type:

bool

Examples

Basic image writing:

>>> import os
>>> import colour
>>> path = os.path.join(
...     colour.__path__[0],
...     "io",
...     "tests",
...     "resources",
...     "CMS_Test_Pattern.exr",
... )
>>> image = read_image(path)
>>> path = os.path.join(
...     colour.__path__[0],
...     "io",
...     "tests",
...     "resources",
...     "CMSTestPattern.tif",
... )
>>> write_image_OpenImageIO(image, path)
True

Advanced image writing while setting attributes:

>>> compression = Image_Specification_Attribute("Compression", "none")
>>> write_image_OpenImageIO(image, path, "uint8", [compression])
...
True

Writing an “ACES” compliant “EXR” file:

>>> from OpenImageIO import TypeDesc
>>> chromaticities = (
...     0.7347,
...     0.2653,
...     0.0,
...     1.0,
...     0.0001,
...     -0.077,
...     0.32168,
...     0.33767,
... )
>>> attributes = [
...     Image_Specification_Attribute("openexr:ACESContainerPolicy", "relaxed"),
...     Image_Specification_Attribute(
...         "chromaticities", chromaticities, TypeDesc("float[8]")
...     ),
...     Image_Specification_Attribute("compression", "none"),
... ]
>>> write_image_OpenImageIO(image, path, attributes=attributes)
True

Notes

  • When using openexr:ACESContainerPolicy with relaxed mode, OpenImageIO automatically sets the colorInteropId attribute to lin_ap0_scene for ACES-compliant files.

  • The acesImageContainerFlag attribute should not be set manually in OpenImageIO 3.1.7.0+, as it triggers strict ACES validation. Use openexr:ACESContainerPolicy instead.