> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/datadesigner/llms.txt.
> For full documentation content, see https://docs.nvidia.com/nemo/datadesigner/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/datadesigner/_mcp/server.

# data\_designer.config.utils.image\_helpers

Helper utilities for working with images.

## Module Contents

### Classes

| Name                                                               | Description                                 |
| ------------------------------------------------------------------ | ------------------------------------------- |
| [`ImageFormat`](#data_designerconfigutilsimage_helpersimageformat) | Supported image formats for image modality. |

### Functions

| Name                                                                                                 | Description                                                           |
| ---------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| [`is_image_diffusion_model`](#data_designerconfigutilsimage_helpersis_image_diffusion_model)         | Return True if the model is a diffusion-based image generation model. |
| [`extract_base64_from_data_uri`](#data_designerconfigutilsimage_helpersextract_base64_from_data_uri) | Extract base64 from data URI or return as-is.                         |
| [`decode_base64_image`](#data_designerconfigutilsimage_helpersdecode_base64_image)                   | Decode base64 string to image bytes.                                  |
| [`detect_image_format`](#data_designerconfigutilsimage_helpersdetect_image_format)                   | Detect image format from bytes.                                       |
| [`is_image_path`](#data_designerconfigutilsimage_helpersis_image_path)                               | Check if a string is an image file path.                              |
| [`is_base64_image`](#data_designerconfigutilsimage_helpersis_base64_image)                           | Check if a string is base64-encoded image data.                       |
| [`is_image_url`](#data_designerconfigutilsimage_helpersis_image_url)                                 | Check if a string is an image URL.                                    |
| [`load_image_path_to_base64`](#data_designerconfigutilsimage_helpersload_image_path_to_base64)       | Load an image from a file path and return as base64.                  |
| [`load_image_url_to_base64`](#data_designerconfigutilsimage_helpersload_image_url_to_base64)         | Download an image from a URL and return as base64.                    |
| [`aload_image_url_to_base64`](#data_designerconfigutilsimage_helpersaload_image_url_to_base64)       | Download an image from a URL asynchronously and return as base64.     |
| [`validate_image`](#data_designerconfigutilsimage_helpersvalidate_image)                             | Validate that an image file is readable and not corrupted.            |

### Data

[`IMAGE_FORMAT_MAGIC_BYTES`](#data_designerconfigutilsimage_helpersimage_format_magic_bytes)
[`_PIL_FORMAT_TO_IMAGE_FORMAT`](#data_designerconfigutilsimage_helpers_pil_format_to_image_format)
[`_BASE64_PATTERN`](#data_designerconfigutilsimage_helpers_base64_pattern)
[`IMAGE_DIFFUSION_MODEL_PATTERNS`](#data_designerconfigutilsimage_helpersimage_diffusion_model_patterns)
[`SUPPORTED_IMAGE_EXTENSIONS`](#data_designerconfigutilsimage_helperssupported_image_extensions)

### API

```python
class data_designer.config.utils.image_helpers.ImageFormat
```

**Bases**: `data_designer.config.utils.type_helpers.StrEnum`

Supported image formats for image modality.

**Initialization:**

Initialize self.  See help(type(self)) for accurate signature.

```python
PNG = png
```

```python
JPG = jpg
```

```python
JPEG = jpeg
```

```python
GIF = gif
```

```python
WEBP = webp
```

```python
IMAGE_FORMAT_MAGIC_BYTES
```

```python
_BASE64_PATTERN = compile(...)
```

```python
IMAGE_DIFFUSION_MODEL_PATTERNS = ('dall-e-', 'dalle', 'stable-diffusion', 'sd-', 'sd_', 'imagen', 'gpt-image-')
```

```python
SUPPORTED_IMAGE_EXTENSIONS
```

```python
data_designer.config.utils.image_helpers.is_image_diffusion_model(model_name: str) -> bool
```

Return True if the model is a diffusion-based image generation model.

**Parameters:**

Model name or identifier (e.g. from provider).

**Returns:**

`bool`

True if the model is detected as diffusion-based, False otherwise.

```python
data_designer.config.utils.image_helpers.extract_base64_from_data_uri(data: str) -> str
```

Extract base64 from data URI or return as-is.

Handles data URIs like "data:image/png;base64,iVBORw0..." and returns
just the base64 portion.

**Parameters:**

Data URI (e.g., "data:image/png;base64,XXX") or plain base64

**Returns:**

`str`

Base64 string without data URI prefix

**Raises:**

If data URI format is invalid

```python
data_designer.config.utils.image_helpers.decode_base64_image(base64_data: str) -> bytes
```

Decode base64 string to image bytes.

Automatically handles data URIs by extracting the base64 portion first.

**Parameters:**

Base64 string (with or without data URI prefix)

**Returns:**

`bytes`

Decoded image bytes

**Raises:**

If base64 data is invalid

```python
data_designer.config.utils.image_helpers.detect_image_format(image_bytes: bytes) -> data_designer.config.utils.image_helpers.ImageFormat
```

Detect image format from bytes.

Uses magic bytes for fast detection, falls back to PIL for robust detection.

**Parameters:**

Image data as bytes

**Returns:**

`data_designer.config.utils.image_helpers.ImageFormat`

Detected ImageFormat

**Raises:**

If the image format cannot be determined

```python
data_designer.config.utils.image_helpers.is_image_path(value: str) -> bool
```

Check if a string is an image file path.

**Parameters:**

String to check

**Returns:**

`bool`

True if the string looks like an image file path, False otherwise

```python
data_designer.config.utils.image_helpers.is_base64_image(value: str) -> bool
```

Check if a string is base64-encoded image data.

**Parameters:**

String to check

**Returns:**

`bool`

True if the string looks like base64-encoded image data, False otherwise

```python
data_designer.config.utils.image_helpers.is_image_url(value: str) -> bool
```

Check if a string is an image URL.

**Parameters:**

String to check

**Returns:**

`bool`

True if the string looks like an image URL, False otherwise

```python
data_designer.config.utils.image_helpers.load_image_path_to_base64(
    image_path: str,
    base_path: str | None = None
) -> str | None
```

Load an image from a file path and return as base64.

**Parameters:**

Relative or absolute path to the image file.

Optional base path to resolve relative paths from.

**Returns:**

`str | None`

Base64-encoded image data or None if loading fails.

```python
data_designer.config.utils.image_helpers.load_image_url_to_base64(
    url: str,
    timeout: int = 60
) -> str
```

Download an image from a URL and return as base64.

**Parameters:**

HTTP(S) URL pointing to an image.

Request timeout in seconds.

**Returns:**

`str`

Base64-encoded image data.

**Raises:**

If the download fails with a non-2xx status.

```python
data_designer.config.utils.image_helpers.aload_image_url_to_base64(
    url: str,
    timeout: int = 60
) -> str
```

Download an image from a URL asynchronously and return as base64.

**Parameters:**

HTTP(S) URL pointing to an image.

Request timeout in seconds.

**Returns:**

`str`

Base64-encoded image data.

**Raises:**

If the download fails with a non-2xx status.

```python
data_designer.config.utils.image_helpers.validate_image(image_path: pathlib.Path) -> None
```

Validate that an image file is readable and not corrupted.

**Parameters:**

Path to image file

**Raises:**

If image is corrupted or unreadable