View Source Anthropic.Messages.Content.Image (anthropic_community v0.4.3)
A module dedicated to processing image content within the Anthropic ecosystem. This module offers functionality for validating, processing, and converting images to base64 encoded strings, ensuring they meet specific criteria such as supported file types and dimensions.
Features
- Supports multiple image formats: JPEG, PNG, GIF, and WEBP.
- Validates images against a set of predefined dimensions and aspect ratios.
- Converts images to a base64 encoded string for easy transmission and storage.
- Provides detailed error handling for various failure scenarios during image processing.
Usage
The primary entry point to the module is the process_image/2
function, which takes an image input
and an input type. The image input can be specified as a binary data, a file path, or a base64 encoded string.
The function returns a structured map with the image's metadata and base64 encoded content if successful,
or an error message if not.
Supported Input Types
:binary
- Direct binary data of the image.:path
- A file system path to the image.:base64
- A base64 encoded string of the image.
Example
Anthropic.Messages.Content.Image.process_image("/path/to/image.png", :path)
This function returns an {:ok, response}
tuple on success, where response
is a map that includes the type,
source type, media type, and base64 data of the image. On failure, it returns {:error, error_message}
.
Summary
Functions
Processes the given image input based on the specified input type and converts it into a base64 encoded string.
Types
@type input_type() :: :binary | :path | :base64
@type mime_type() :: String.t()
@type supported_size() :: {String.t(), dimensions()}
Functions
@spec process_image(image_input(), input_type()) :: process_output()
Processes the given image input based on the specified input type and converts it into a base64 encoded string.
Parameters
image_input
: The image input, which can be binary data, a file path, or a base64 encoded string.input_type
: A symbol indicating the type of theimage_input
(:binary
,:path
,:base64
).
Returns
An {:ok, response}
tuple containing the processed image information or {:error, reason}
on failure.