class Ollama::Image

end
image = Ollama::Image.for_io(io, path: ‘image.jpg’)
File.open(‘path/to/image.jpg’, ‘rb’) do |io|
@example Creating an image from an IO object
image = Ollama::Image.for_string(‘raw image data’)
@example Creating an image from a string
image = Ollama::Image.for_base64(‘base64encodedstring’, path: ‘image.jpg’)
@example Creating an image from a base64 string
image = Ollama::Image.for_filename(‘path/to/image.jpg’)
@example Creating an image from a file path
including base64 encoded strings, file paths, IO objects, and raw string data.
The Image class provides methods to create image objects from various sources
Represents an image object that can be used in messages sent to the Ollama API.
Ollama::Image

def ==(other)

Returns:
  • (TrueClass, FalseClass) - true if both Image objects have identical

Parameters:
  • other (Ollama::Image) -- the other Image object to compare against
def ==(other)
  @data == other.data
end

def for_base64(data, path: nil)

Returns:
  • (Ollama::Image) - a new Image instance initialized with the

Parameters:
  • path (String, nil) -- the optional file path associated with the image
  • data (String) -- the base64 encoded image data
def for_base64(data, path: nil)
  obj = new(data)
  obj.path = path
  obj
end

def for_filename(path)

Returns:
  • (Ollama::Image) - a new Image instance initialized with the

Parameters:
  • path (String) -- the file system path to the image file
def for_filename(path)
  File.open(path, 'rb') { |io| for_io(io, path:) }
end

def for_io(io, path: nil)

Returns:
  • (Ollama::Image) - a new Image instance initialized with the IO

Parameters:
  • path (String, nil) -- the optional file path associated with the image
  • io (IO) -- the IO object to read image data from
def for_io(io, path: nil)
  path ||= io.path
  for_string(io.read, path:)
end

def for_string(string, path: nil)

Returns:
  • (Ollama::Image) - a new Image instance initialized with the

Parameters:
  • path (String, nil) -- the optional file path associated with the image
  • string (String) -- the raw string data to be converted into an image
def for_string(string, path: nil)
  for_base64(Base64.encode64(string), path:)
end

def initialize(data)

Parameters:
  • data (String) -- the image data to store in the object
def initialize(data)
  @data = data
end

def to_s

Returns:
  • (String) - the raw image data contained within the image object
def to_s
  @data
end