Image Buffer Types (imbuf.types)

This module provides access to image buffer types.

Note

Image buffer is also the structure used by bpy.types.Image ID type to store and manipulate image data at runtime.

class imbuf.types.ImBuf
clear_buffer(type)

Free pixel data of the given type.

Parameters:

type (Literal['BYTE', 'FLOAT']) – The buffer type.

copy()

Return a copy of the image.

Returns:

A copy of the image.

Return type:

ImBuf

crop(min, max)

Crop the image in-place.

Parameters:
  • min (tuple[int, int]) – Minimum pixel coordinates (X, Y), inclusive.

  • max (tuple[int, int]) – Maximum pixel coordinates (X, Y), inclusive.

ensure_buffer(type)

Ensure the image has pixel data of the given type. If absent, it is allocated and converted from the other buffer when available.

Parameters:

type (Literal['BYTE', 'FLOAT']) – The buffer type.

free()

Clear image data immediately (causing an error on re-use).

has_buffer(type)

Return whether the image has pixel data of the given type.

Parameters:

type (Literal['BYTE', 'FLOAT']) – The buffer type.

Returns:

True if the buffer exists.

Return type:

bool

resize(size, *, method='FAST')

Resize the image in-place.

Parameters:
  • size (tuple[int, int]) – New size.

  • method (str) – Method of resizing (‘FAST’, ‘BILINEAR’).

with_buffer(type, *, write=False, region=None)

Return a context manager that yields a memoryview of the image’s pixel data.

Usage:

with image.with_buffer('BYTE', write=True) as buf:
    buf[0] = 255  # set red channel of first pixel
Parameters:
  • type (Literal['BYTE', 'FLOAT']) – The buffer type.

  • write (bool) – When true the buffer is writable.

  • region (tuple[tuple[int, int], tuple[int, int]] | None) – Optional sub-region ((x_min, y_min), (x_max, y_max)). When set the memoryview is 2D (rows x columns), clamped to image bounds.

Returns:

A context manager yielding a memoryview of pixel data.

Return type:

ImBufBuffer

channels

Number of color channels.

Type:

int

compress

Compression level for formats that support lossless compression levels (0 - 100, clamped).

Type:

int

file_type

The file type identifier.

Type:

str

filepath

Filepath associated with this image.

Type:

str | bytes

planes

Number of bits per pixel for the byte buffer. Used when reading and writing image files.

  • 8: Gray-scale.

  • 16: Gray-scale with alpha.

  • 24: RGB.

  • 32: RGBA.

Note

This value may be set by the file format on load, and determines how many channels are written on save.

Type:

int

ppm

Pixels per meter.

Type:

tuple[float, float]

quality

Quality for formats that support lossy compression (0 - 100, clamped).

Type:

int

size

Size of the image in pixels.

Type:

tuple[int, int]

class imbuf.types.ImBufBuffer
class imbuf.types.ImBufFileType
file_extensions

Undocumented, consider contributing.

has_read_file

Undocumented, consider contributing.

has_read_memory

Undocumented, consider contributing.

has_write_file

Undocumented, consider contributing.

has_write_memory

Undocumented, consider contributing.

id

Undocumented, consider contributing.