Skip to content

ImageFile

ImageFile is inherited from File with additional methods for working with image files.

ImageFile is generated when a DataChain is created from storage, using type="image" param:

from datachain import DataChain

dc = DataChain.from_storage("s3://bucket-name/", type="image")

ImageFile

ImageFile(**kwargs)

Bases: File

DataModel for reading image files.

Source code in datachain/lib/file.py
def __init__(self, **kwargs):
    super().__init__(**kwargs)
    self._catalog = None
    self._caching_enabled: bool = False

read

read()

Returns PIL.Image.Image object.

Source code in datachain/lib/file.py
def read(self):
    """Returns `PIL.Image.Image` object."""
    fobj = super().read()
    return PilImage.open(BytesIO(fobj))

save

save(destination: str)

Writes it's content to destination

Source code in datachain/lib/file.py
def save(self, destination: str):
    """Writes it's content to destination"""
    destination = stringify_path(destination)

    client: Client = self._catalog.get_client(destination)
    with client.fs.open(destination, mode="wb") as f:
        self.read().save(f)

Image

Bases: DataModel

A data model representing metadata for an image file.

Attributes:

  • width (int) โ€“

    The width of the image in pixels. Defaults to -1 if unknown.

  • height (int) โ€“

    The height of the image in pixels. Defaults to -1 if unknown.

  • format (str) โ€“

    The format of the image file (e.g., 'jpg', 'png'). Defaults to an empty string.