Method: Vips::Image.new_from_buffer

Defined in:
lib/vips8/image.rb

.new_from_buffer(data, option_string, opts = {}) ⇒ Image

Create a new Vips::Image for an image encoded in a format, such as JPEG, in a memory string. Load options may be passed encoded as strings, or appended as a hash. For example:

image = Vips::new_from_from_buffer memory_buffer, "shrink=2"

or alternatively:

image = Vips::new_from_from_buffer memory_buffer, "", :shrink => 2

The options available depend on the file format. Try something like:

$ vips jpegload_buffer

at the command-line to see the available options. Only JPEG, PNG and TIFF images can be read from memory buffers.

Loading is fast: only enough of the image is loaded to be able to fill out the header. Pixels will only be processed when they are needed.

Parameters:

  • data (String)

    the data to load from

  • option_string (String)

    load options as a string

  • opts (Hash) (defaults to: {})

    set of options

Options Hash (opts):

  • :disc (Boolean) — default: true

    Open large images via a temporary disc file

  • :access (Vips::Access) — default: :random

    Access mode for file

Returns:

  • (Image)

    the loaded image



464
465
466
467
468
469
470
471
# File 'lib/vips8/image.rb', line 464

def self.new_from_buffer(data, option_string, opts = {})
    loader = Vips::Foreign.find_load_buffer data
    if loader == nil
        raise Vips::Error
    end

    Vips::call_base loader, nil, option_string, [data, opts]
end