Kreuzberg.Image (kreuzberg v4.4.2)

Copy Markdown View Source

Structure representing an extracted image from a document.

Matches the Rust ExtractedImage struct.

Fields

  • :data - Raw binary image data (PNG, JPEG, WebP, etc.)
  • :format - Image format string ("png", "jpeg", "webp", etc.)
  • :image_index - Zero-indexed position of image in the document/page
  • :page_number - Page number where image was found
  • :width - Image width in pixels
  • :height - Image height in pixels
  • :colorspace - Color space (e.g., "RGB", "CMYK", "Gray")
  • :bits_per_component - Bits per color component (e.g., 8, 16)
  • :is_mask - Whether this image is a mask image
  • :description - Optional description of the image
  • :ocr_result - Nested OCR extraction result map
  • :bounding_box - Bounding box coordinates if available

Summary

Functions

Creates an Image struct from a map.

Returns whether the image has binary data.

Creates a new Image struct.

Converts an Image struct to a map.

Types

t()

@type t() :: %Kreuzberg.Image{
  bits_per_component: non_neg_integer() | nil,
  bounding_box: map() | nil,
  colorspace: String.t() | nil,
  data: binary(),
  description: String.t() | nil,
  format: String.t(),
  height: non_neg_integer() | nil,
  image_index: non_neg_integer(),
  is_mask: boolean(),
  ocr_result: Kreuzberg.ExtractionResult.t() | nil,
  page_number: non_neg_integer() | nil,
  width: non_neg_integer() | nil
}

Functions

from_map(data)

@spec from_map(map()) :: t()

Creates an Image struct from a map.

Handles bytes::Bytes serde serialization where binary data arrives as a list of u8 integers, converting it to Elixir binary.

Examples

iex> Kreuzberg.Image.from_map(%{"format" => "png", "image_index" => 0, "width" => 800})
%Kreuzberg.Image{format: "png", image_index: 0, width: 800}

has_data?(image)

@spec has_data?(t()) :: boolean()

Returns whether the image has binary data.

new(format, opts \\ [])

@spec new(
  String.t(),
  keyword()
) :: t()

Creates a new Image struct.

Parameters

  • format - The image format (e.g., "png", "jpeg")
  • opts - Optional keyword list of additional fields

to_map(image)

@spec to_map(t()) :: map()

Converts an Image struct to a map.