bootstack.images.Image#

class bootstack.images.Image(*, pil=None, path=None, data=None, icon=None)#

Bases: object

A toolkit-free image handle, rendered for display only when used.

An Image carries a source — a file, raw bytes, an in-memory picture, or a deferred icon — without creating any display resource up front. The picture is rendered the moment it is handed to a widget (via image=), so a handle can be built before an application is running and shared across widgets.

Build one with Image.open, Image.from_bytes, or Image.from_pil, or use get_icon for a Bootstrap icon. Read width and height at any time.

File and byte sources accept the common raster image formats — PNG, JPEG, GIF, BMP, TIFF, WebP, and ICO. (Animated formats load their first frame.)

property height: int#

The height of the image in pixels.

property width: int#

The width of the image in pixels.

classmethod from_bytes(data)#

Create an image handle from raw, encoded image bytes.

Parameters:

data (bytes) – Encoded image bytes in a common raster format — PNG, JPEG, GIF, BMP, TIFF, WebP, or ICO — for example, an embedded resource or a downloaded file.

Returns:

A new image handle.

Return type:

Image

classmethod from_pil(image)#

Create an image handle from an in-memory Pillow image.

Useful when you have already loaded or manipulated a picture with Pillow (resizing, filtering, compositing) and want to display the result.

Parameters:

image (_PILImage) – A Pillow image object to wrap.

Returns:

A new image handle.

Return type:

Image

classmethod open(path)#

Create an image handle from a file on disk.

The file is decoded lazily, so the path is not read until the image is displayed or its size is queried.

Parameters:

path (str | Path) – Path to the image file. Supports ~ expansion. Accepts the common raster formats — PNG, JPEG, GIF, BMP, TIFF, WebP, and ICO.

Returns:

A new image handle.

Return type:

Image