Kreuzberg.Image (kreuzberg v4.0.8)
View SourceStructure representing an extracted image with optional OCR results.
Contains binary image data and metadata extracted from documents, along with OCR text results when OCR processing is enabled.
Fields
:data- Binary image data (PNG, JPEG, WebP, etc.):format- Image format as string ("png", "jpeg", "webp", etc.):width- Image width in pixels:height- Image height in pixels:mime_type- MIME type of the image (e.g., "image/png"):ocr_text- Text extracted from image via OCR:page_number- Page number where image appears:file_size- Size of image data in bytes:dpi- Dots per inch of the image
Examples
iex> image = %Kreuzberg.Image{
...> format: "png",
...> width: 800,
...> height: 600,
...> data: <<...>>,
...> ocr_text: "Extracted text from image"
...> }
iex> image.format
"png"
Summary
Functions
Returns the aspect ratio (width / height) of the image.
Creates an Image struct from a map.
Returns whether the image has binary data.
Creates a new Image struct with required format field.
Converts an Image struct to a map.
Types
Functions
Returns the aspect ratio (width / height) of the image.
Parameters
image- AnImagestruct
Returns
The aspect ratio as a float, or nil if dimensions not available.
Examples
iex> image = %Kreuzberg.Image{width: 1920, height: 1080}
iex> Kreuzberg.Image.aspect_ratio(image)
1.7777777777777777
iex> image = %Kreuzberg.Image{format: "png"}
iex> Kreuzberg.Image.aspect_ratio(image)
nil
Creates an Image struct from a map.
Converts a plain map (typically from NIF/Rust) into a proper struct.
Parameters
data- A map containing image fields
Returns
An Image struct with matching fields populated.
Examples
iex> image_map = %{
...> "format" => "png",
...> "width" => 1024,
...> "height" => 768
...> }
iex> Kreuzberg.Image.from_map(image_map)
%Kreuzberg.Image{
format: "png",
width: 1024,
height: 768
}
Returns whether the image has binary data.
Parameters
image- AnImagestruct
Returns
true if image has data, false otherwise.
Examples
iex> image = %Kreuzberg.Image{format: "png", data: <<1, 2, 3>>}
iex> Kreuzberg.Image.has_data?(image)
true
iex> image = %Kreuzberg.Image{format: "png"}
iex> Kreuzberg.Image.has_data?(image)
false
Creates a new Image struct with required format field.
Parameters
format- The image format (e.g., "png", "jpeg")opts- Optional keyword list with::data- Binary image data:width- Image width in pixels:height- Image height in pixels:mime_type- MIME type:ocr_text- OCR extracted text:page_number- Page number:file_size- File size in bytes:dpi- DPI setting
Returns
An Image struct with the provided format and options.
Examples
iex> Kreuzberg.Image.new("png")
%Kreuzberg.Image{format: "png"}
iex> Kreuzberg.Image.new(
...> "jpeg",
...> width: 1920,
...> height: 1080,
...> dpi: 150
...> )
%Kreuzberg.Image{
format: "jpeg",
width: 1920,
height: 1080,
dpi: 150
}
Converts an Image struct to a map.
Useful for serialization and passing to external systems.
Parameters
image- AnImagestruct
Returns
A map with string keys representing all fields.
Examples
iex> image = %Kreuzberg.Image{format: "png", width: 800}
iex> Kreuzberg.Image.to_map(image)
%{
"format" => "png",
"width" => 800,
"data" => nil,
...
}