Skip to content

daft.functions.encode_image#

encode_image #

encode_image(image: Expression, image_format: str | ImageFormat) -> Expression

Encode an image column as the provided image file format, returning a binary column of encoded bytes.

Parameters:

Name Type Description Default
image Image Expression

The image to encode.

required
image_format str | ImageFormat

The image file format into which the images will be encoded.

required

Returns:

Name Type Description
Expression Binary Expression

An expression representing a binary column of encoded image bytes.

Source code in daft/functions/image.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def encode_image(image: Expression, image_format: str | ImageFormat) -> Expression:
    """Encode an image column as the provided image file format, returning a binary column of encoded bytes.

    Args:
        image (Image Expression): The image to encode.
        image_format (str | ImageFormat): The image file format into which the images will be encoded.

    Returns:
        Expression (Binary Expression): An expression representing a binary column of encoded image bytes.
    """
    if isinstance(image_format, str):
        image_format = ImageFormat.from_format_string(image_format.upper())
    if not isinstance(image_format, ImageFormat):
        raise ValueError(f"image_format must be a string or ImageFormat variant, but got: {image_format}")
    return Expression._call_builtin_scalar_fn("image_encode", image, image_format=image_format)