DocumentationAPI Reference📓 Tutorials🧑‍🍳 Cookbook🤝 Integrations💜 Discord🎨 Studio
API Reference

Image Converters

Various image conversion components.

Module haystack_experimental.components.image_converters.file_to_image

ImageFileToImageContent

Converts image files to ImageContent objects.

ImageFileToImageContent.__init__

def __init__(*,
             detail: Optional[Literal["auto", "high", "low"]] = None,
             size: Optional[Tuple[int, int]] = None)

Create the ImageFileToImageContent component.

Arguments:

  • detail: Optional detail level of the image (only supported by OpenAI). One of "auto", "high", or "low". This will be passed to the created ImageContent objects.
  • size: 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, which is beneficial when working with models that have resolution constraints or when transmitting images to remote services.

ImageFileToImageContent.run

@component.output_types(image_contents=List[ImageContent])
def run(sources: List[Union[str, Path, ByteStream]],
        meta: Optional[Union[Dict[str, Any], List[Dict[str, Any]]]] = None,
        *,
        detail: Optional[Literal["auto", "high", "low"]] = None,
        size: Optional[Tuple[int, int]] = None)

Converts files to ImageContent objects.

Arguments:

  • sources: List of file paths or ByteStream objects to convert.
  • meta: 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 detail level of the image (only supported by OpenAI). One of "auto", "high", or "low". This will be passed to the created ImageContent objects. If not provided, the detail level will be the one set in the constructor.
  • size: 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, which is beneficial when working with models that have resolution constraints or when transmitting images to remote services. If not provided, the size value will be the one set in the constructor.

Returns:

A dictionary with the following keys:

  • image_contents: A list of ImageContent objects.

Module haystack_experimental.components.image_converters.pdf_to_image

PDFToImageContent

Converts PDF files to ImageContent objects.

PDFToImageContent.__init__

def __init__(*,
             detail: Optional[Literal["auto", "high", "low"]] = None,
             size: Optional[Tuple[int, int]] = None,
             page_range: Optional[List[Union[str, int]]] = None)

Create the PDFToImageContent component.

Arguments:

  • detail: Optional detail level of the image (only supported by OpenAI). One of "auto", "high", or "low". This will be passed to the created ImageContent objects.
  • size: 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, which is beneficial when working with models that have resolution constraints or when transmitting images to remote services.
  • page_range: List of page numbers and/or page ranges to convert to images. Page numbers start at 1. If None, all pages in the PDF will be converted. Pages outside the valid range (1 to number of pages) will be skipped with a warning. For example, page_range=[1, 3] will convert only the first and third pages of the document. It also accepts printable range strings, e.g.: ['1-3', '5', '8', '10-12'] will convert pages 1, 2, 3, 5, 8, 10, 11, 12.

PDFToImageContent.run

@component.output_types(image_contents=List[ImageContent])
def run(sources: List[Union[str, Path, ByteStream]],
        meta: Optional[Union[Dict[str, Any], List[Dict[str, Any]]]] = None,
        *,
        detail: Optional[Literal["auto", "high", "low"]] = None,
        size: Optional[Tuple[int, int]] = None,
        page_range: Optional[List[Union[str, int]]] = None)

Converts files to ImageContent objects.

Arguments:

  • sources: List of file paths or ByteStream objects to convert.
  • meta: 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 detail level of the image (only supported by OpenAI). One of "auto", "high", or "low". This will be passed to the created ImageContent objects. If not provided, the detail level will be the one set in the constructor.
  • size: 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, which is beneficial when working with models that have resolution constraints or when transmitting images to remote services. If not provided, the size value will be the one set in the constructor.
  • page_range: List of page numbers and/or page ranges to convert to images. Page numbers start at 1. If None, all pages in the PDF will be converted. Pages outside the valid range (1 to number of pages) will be skipped with a warning. For example, page_range=[1, 3] will convert only the first and third pages of the document. It also accepts printable range strings, e.g.: ['1-3', '5', '8', '10-12'] will convert pages 1, 2, 3, 5, 8, 10, 11, 12. If not provided, the page_range value will be the one set in the constructor.

Returns:

A dictionary with the following keys:

  • image_contents: A list of ImageContent objects.