Updated on 2025-12-19 GMT+08:00

Images

Images are processed internally using the Pillow library. By obtaining a Python imaging library (PIL) image object, you can process images through the PIL library. Supported image formats include JPEG, PNG, and BMP.

Table 1 Properties

Property

Type

Description

filename

str

File name or path of the image (if loaded from a file).

format

str

Image format (e.g. PNG, JPEG).

height

int

Image height in pixels.

width

int

Image width in pixels.

data

bytes

Image data.

pil_image

PIL_Image.Image

Dynamic property: Returns the Pillow image object (auto-decoded from data).

Table 2 Methods

Method

Parameter

Return Value

Description

__init__

filename: Union[str, os.PathLike] = None

data: Union[str, PIL.Image] = None

format: Optional[str] = None

None

Constructor: Loads an image from a file (filename) or data (data), supporting bytes or Pillow objects.

to_numpy

np.ndarray

Converts the image to a NumPy array (float32).

resize

new_shape: tuple[int, int]

Image

Returns a new resized image based on the specified dimensions.

show

None

Displays the image using Pillow's default viewer.

to_thumbnail

size: tuple[int, int] = (100, 100)

Image

Generates a thumbnail with the specified size.

from_struct (class method)

obj: dict (must include the fields filename, data, and format)

Image

Creates an Image object from a structured dictionary.