Method: Vips::Image#write_to_buffer

Defined in:
lib/vips8/image.rb

#write_to_buffer(format_string, opts = {}) ⇒ String

Write this image to a memory buffer. Save options may be encoded in the format_string or given as a hash. For example:

buffer = image.write_to_buffer ".jpg[Q=90]"

or equivalently:

image.write_to_buffer ".jpg", :Q => 90

The full set of save options depend on the selected saver. Try something like:

$ vips jpegsave

to see all the available options.

Parameters:

  • format_string (String)

    save format plus options

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

    set of options

Options Hash (opts):

  • :strip (Boolean) — default: false

    Strip all metadata from image

  • :background (Array<Float>) — default: 0

    Background colour to flatten alpha against, if necessary

Returns:

  • (String)

    the image saved in the specified format

[View source]

604
605
606
607
608
609
610
611
612
613
614
615
616
617
# File 'lib/vips8/image.rb', line 604

def write_to_buffer(format_string, opts = {})
    filename = Vips::filename_get_filename format_string
    option_string = Vips::filename_get_options format_string
    saver = Vips::Foreign.find_save_buffer filename
    if saver == nil
        raise Vips::Error, "No known saver for '#{filename}'."
    end

    buffer = Vips::call_base saver, self, option_string, [opts]

    write_gc

    return buffer
end