ImageMode

class toasty.image.ImageMode(value)[source]

Bases: enum.Enum

Allowed image “modes”, describing their pixel data formats.

These align with PIL modes when possible, but we expect to need to support modes that aren’t present in PIL (namely, float64). There are also various obscure PIL modes that we do not support.

Attributes Summary

F16x3

F32

F64

RGB

RGBA

Methods Summary

make_maskable_buffer(buf_height, buf_width)

Return a new, uninitialized buffer of the specified shape, with a mode compatible with this one but able to accept undefined values.

try_as_pil()

Attempt to convert this mode into a PIL image mode string.

Attributes Documentation

F16x3 = 'F16x3'
F32 = 'F'
F64 = 'D'
RGB = 'RGB'
RGBA = 'RGBA'

Methods Documentation

make_maskable_buffer(buf_height, buf_width)[source]

Return a new, uninitialized buffer of the specified shape, with a mode compatible with this one but able to accept undefined values.

Parameters
buf_heightint

The height of the new buffer

buf_widthint

The width of the new buffer

Returns
An uninitialized Image instance.

Notes

“Maskable” means that the buffer can accommodate undefined values. If the image is RGB or RGBA, that means that the buffer will have an alpha channel. If the image is scientific, that means that the buffer will be able to accept NaNs.

try_as_pil()[source]

Attempt to convert this mode into a PIL image mode string.

Returns
A PIL image mode string, or None if there is no exact counterpart.