You need to enable JavaScript to run this app.
Lake AI Service

Lake AI Service

Copy page
Download PDF
Image processing
Image format conversion
Copy page
Download PDF
Image format conversion

Operator introduction

Description

The image format conversion processor supports conversion between multiple input and output formats and allows adjustment of output quality.

Key features

  • Support for multiple image formats:
    • Input: URL address, Base64 encoding, binary stream
    • Output: PNG, JPEG/JPG, WebP
  • Quality adjustment:
    • Supports adjusting the output quality of lossy compression formats (JPEG, WebP)
    • The quality range can be set from -1 to 100; -1 indicates using the default value
  • Intelligent format processing:
    • Automatically handles transparency channels (JPEG does not support transparency channels)
    • Automatically handles color mode conversion (such as CMYK to RGB)
  • Dual output modes:
    • Direct output as Base64 encoding
    • TOS/local persistent storage

Caution and prerequisites

Details

Caution and prerequisites

Costs

Before calling an operator, you need to understand the model invocation costs associated with using the operator. For details, see Large model invocation billing.

Authentication (API Key)

Before calling an operator, you need to generate an API Key for operator invocation. It is recommended to configure the API Key as an environment variable to ensure safer operator calls. For details, see Obtain and configure API Key.

BaseURL

Before calling an operator, you need to determine the BaseURL for operator invocation based on the region where your current LAS service is deployed. This is used to configure the path parameter values for operator calls.
For details, see Obtain the Base URL. The Examples below are for reference only; when making actual calls, replace the path values with those corresponding to your region.

Daft invocation

Operator parameters

Input

Input column name

Note

images

An array containing input images; supports URL, base64, and binary formats

images_name

Optional parameter; an array containing image identifier names, used to generate output file names. It is recommended to provide this to ensure file name uniqueness and not include a suffix; if not provided, a random name will be generated for images whose names cannot be parsed.

Output

An array of dictionaries containing processing results; each element includes:

  • base64: Base64 encoding of the converted image;
  • image_path: Local/TOS storage path (valid when the output directory is configured)

Parameters

If a parameter does not have a default value, it is required

Parameter name

Type

Default value

Description

output_format

str

"png"

The format of the output image.
Description: The format of the output image; supports multiple common image formats.
Optional values: ["png", "jpg", "jpeg", "webp"]
Default value: "png"

image_suffix

str

""

The suffix for images saved to TOS or locally.
Description: The suffix for images saved to TOS or locally; if not set, it will be automatically generated based on output_format.
Default value: ""

tos_dir

str

The folder path in TOS for saving images.
Description: The TOS path where the converted images are saved; if not set, the converted images will not be saved to TOS.
Default value: ""

local_dir

str

The local folder path for saving images.
Description: The local storage directory for the converted image. If left empty, the converted image will not be saved locally.
Default value: ""

image_src_type

str

"image_url"

The input image format type. Supported types:

  • URL address (image_url)
  • Base64 encoding (image_base64)
  • Binary stream (image_binary)

Description: The format type of the input image.
Optional values: ["image_url", "image_base64", "image_binary"]
Default value: "image_url"

quality

int

-1

The output image quality (applicable only to lossy compression formats).
Description: The output image quality, range -1–100, applicable only to lossy compression formats such as jpg, jpeg, and webp.
When set to -1, the built-in default quality value for each format will be used (JPEG defaults to 75, WebP defaults to 80).
Default value: -1

Examples

The following code demonstrates how to use daft to run the operator for image format conversion.

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.image.image_format_convert import ImageFormatConvert
from daft.las.functions.udf import las_udf

if __name__ == "__main__":
    if os.getenv("DAFT_RUNNER", "native") == "ray":
        import logging

        import ray

        def configure_logging():
            logging.basicConfig(
                level=logging.INFO,
                format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S.%s".format(),
            )
            logging.getLogger("tracing.span").setLevel(logging.WARNING)
            logging.getLogger("daft_io.stats").setLevel(logging.WARNING)
            logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING)

        ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging})
        daft.set_runner_ray()
    daft.set_execution_config(actor_udf_ready_timeout=600)
    daft.set_execution_config(min_cpu_per_task=0)


    tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com")
    samples = {
        "image": [
            f"https://{tos_dir_url}/public/shared_image_dataset/cat_ip_adapter.jpeg"
        ],
        "image_name": ["cat_ip_adapter"],
    }

    output_format = "png"
    image_suffix = ""
    tos_dir = ""
    local_dir = ""
    image_src_type = "image_url"
    quality = -1
    num_gpus = 0

    ds = daft.from_pydict(samples)
    ds = ds.with_column(
        "image_format_convert",
        las_udf(
            ImageFormatConvert,
            construct_args={
                "output_format": output_format,
                "image_suffix": image_suffix,
                "tos_dir": tos_dir,
                "local_dir": local_dir,
                "image_src_type": image_src_type,
                "quality": quality,
            },
            num_gpus=num_gpus,
            batch_size=1,
        )(col("image"), col("image_name")),
    )

    ds.show()

    # ╭────────────────────────────────┬────────────────┬────────────────────────────────────────╮
    # │ image                          ┆ image_name     ┆ image_format_convert                   │
    # │ ---                            ┆ ---            ┆ ---                                    │
    # │ Utf8                           ┆ Utf8           ┆ Struct[base64: Utf8, image_path: Utf8] │
    # ╞════════════════════════════════╪════════════════╪════════════════════════════════════════╡
    # │ https://las-cn-beijing-public… ┆ cat_ip_adapter ┆ {base64: iVBORw0KGgoAAAANSUhE…         │
    # ╰────────────────────────────────┴────────────────┴────────────────────────────────────────╯
Last updated: 2026.05.24 15:21:36