Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Eventual Inc Daft Decode Image

From Leeroopedia
Revision as of 14:52, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Eventual_Inc_Daft_Decode_Image.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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),
)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment