Implementation:Eventual Inc Daft Decode Image
| Knowledge Sources | |
|---|---|
| Domains | Data_Engineering, Computer_Vision |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Concrete tool for decoding binary image data into Image expressions provided by the Daft library.
Description
The decode_image function decodes binary-encoded image data (PNG, JPEG, TIFF, WebP, etc.) into Daft's native Image data type. It converts raw bytes into structured image representations with configurable color mode conversion (default RGB) and error handling. The function can only be applied to Binary expressions that contain encoded image data.
Usage
Import and use this function when you need to decode downloaded image bytes or binary image data from storage into Daft's Image type for downstream processing (resize, crop, embed, etc.).
Code Reference
Source Location
- Repository: Daft
- File:
daft/functions/image.py - Lines: L63-82
Signature
def decode_image(
bytes: Expression,
on_error: Literal["raise", "null"] = "raise",
mode: str | ImageMode | None = ImageMode.RGB,
) -> Expression
Import
from daft.functions import decode_image
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| bytes | Expression (Binary) | Yes | A Binary expression containing encoded image data (e.g., PNG, JPEG bytes). |
| on_error | Literal["raise", "null"] | No | Error handling behavior. "raise" fails on corrupt/unreadable images; "null" returns null and logs a warning. Defaults to "raise".
|
| mode | ImageMode | None | No | Target color mode for decoded images. Defaults to ImageMode.RGB. If None, the mode is inferred from the underlying image data.
|
Outputs
| Name | Type | Description |
|---|---|---|
| return | Expression (Image) | An Image expression containing the decoded image data with pixel values, width, height, and color mode. |
Usage Examples
Basic Usage
import daft
from daft.functions import decode_image
df = daft.from_pydict({"urls": ["https://example.com/image.png"]})
df = df.with_column("image_bytes", daft.col("urls").download())
df = df.with_column("image", decode_image(daft.col("image_bytes")))
df.show()
With Custom Mode and Error Handling
import daft
from daft.functions import decode_image
from daft.daft import ImageMode
df = df.with_column(
"image",
decode_image(daft.col("image_bytes"), on_error="null", mode=ImageMode.RGBA),
)