colour.write_image#
- colour.write_image(image: ArrayLike, path: str, bit_depth: Literal['uint8', 'uint16', 'float16', 'float32', 'float64', 'float128'] = 'float32', method: Literal['Imageio', 'OpenImageIO'] | str = 'OpenImageIO', **kwargs: Any) bool [source]#
Write given image data at given path using given method.
- Parameters:
image (ArrayLike) – Image data.
path (str) – Image path.
bit_depth (Literal['uint8', 'uint16', 'float16', 'float32', 'float64', 'float128']) – Bit depth to write the image at, for the Imageio method, the image data is converted with
colour.io.convert_bit_depth()
definition prior to writing the image.method (Literal['Imageio', 'OpenImageIO'] | str) – Write method, i.e. the image library used for writing images.
attributes – {
colour.io.write_image_OpenImageIO()
}, An array ofcolour.io.ImageAttribute_Specification
class instances used to set attributes of the image.kwargs (Any) –
- Returns:
Definition success.
- Return type:
Notes
If the given method is OpenImageIO but the library is not available writing will be performed by Imageio.
If the given method is Imageio,
kwargs
is passed directly to the wrapped definition.It is possible to control how the image are saved by the Freeimage backend by using the
flags
keyword argument and passing a desired value. See the Load / Save flag constants section in https://sourceforge.net/p/freeimage/svn/HEAD/tree/FreeImage/trunk/Source/FreeImage.h
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(image, path) True
Advanced image writing while setting attributes using OpenImageIO:
>>> compression = ImageAttribute_Specification("Compression", "none") >>> write_image(image, path, bit_depth="uint8", attributes=[compression]) ... True