ImageFileToImageContent
Convert image files to ImageContent objects for multimodal AI processing, including tasks like image captioning or visual question answering.
Basic Information
- Type:
haystack.components.converters.image.ImageFileToImageContent - Components it can connect with:
FilesInput:ImageFileToImageContentcan receive file paths fromFilesInput.ChatPromptBuilder:ImageFileToImageContentcan send image content toChatPromptBuilderfor multimodal prompts.
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| sources | List[Union[str, Path, ByteStream]] | List of image file paths or ByteStream objects to convert. | |
| meta | Optional[Union[Dict[str, Any], List[Dict[str, Any]]]] | None | Optional metadata to attach to the ImageContent objects. This value can be a list of dictionaries or a single dictionary. If it's a single dictionary, its content is added to the metadata of all produced ImageContent objects. If it's a list, its length must match the number of sources as they're zipped together. For ByteStream objects, their meta is added to the output ImageContent objects. |
| detail | Optional[Literal["auto", "high", "low"]] | None | Optional detail level of the image (only supported by OpenAI). This is passed to the created ImageContent objects. If not provided, the detail level is the one set in the constructor. |
| size | Optional[Tuple[int, int]] | None | If provided, resizes the image to fit within the specified dimensions (width, height) while maintaining aspect ratio. If not provided, the size value is the one set in the constructor. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| image_contents | List[ImageContent] | A list of ImageContent objects created from the input image files. |
Overview
ImageFileToImageContent reads image files from various sources and creates ImageContent objects containing the base64-encoded image data along with associated metadata.
It supports various image formats and can optionally resize images and set detail levels for optimization with different AI models. It's particularly useful for preparing images for vision models or other multimodal AI tasks.
Image resizing helps reduce file size, memory usage, and processing time, which is beneficial when working with models that have resolution constraints or when transmitting images to remote services.
Usage Example
Initializing the Component
components:
ImageFileToImageContent:
type: haystack.components.converters.image.file_to_image.ImageFileToImageContent
init_parameters:
detail: high
size: [512, 512]
Parameters
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| detail | Optional[Literal["auto", "high", "low"]] | None | Optional detail level of the image (only supported by OpenAI). Possible values: - "auto" - "high" - "low" This is passed to the created ImageContent objects. |
| size | Optional[Tuple[int, int]] | None | If provided, resizes the image to fit within the specified dimensions (width, height) while maintaining aspect ratio. This reduces file size, memory usage, and processing time. |
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
| sources | List[Union[str, Path, ByteStream]] | List of image file paths or ByteStream objects to convert. | |
| meta | Optional[Union[Dict[str, Any], List[Dict[str, Any]]]] | None | Optional metadata to attach to the ImageContent objects. This value can be a list of dictionaries or a single dictionary. If it's a single dictionary, its content is added to the metadata of all produced ImageContent objects. If it's a list, its length must match the number of sources as they're zipped together. For ByteStream objects, their meta is added to the output ImageContent objects. |
| detail | Optional[Literal["auto", "high", "low"]] | None | Optional detail level of the image (only supported by OpenAI). This will be passed to the created ImageContent objects. If not provided, the detail level will be the one set in the constructor. |
| size | Optional[Tuple[int, int]] | None | If provided, resizes the image to fit within the specified dimensions (width, height) while maintaining aspect ratio. If not provided, the size value will be the one set in the constructor. |
Was this page helpful?