vendor/bundle/ruby/3.0.0/gems/ruby-vips-2.1.4/lib/vips/image.rb
# 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 for JPEG save.
#
# @param format_string [String] save format plus options
# @macro vips.saveopts
# @return [String] the image saved in the specified format
Write this image to a memory buffer. Save options may be encoded in
the format_string or given as a hash. For example.



or equivalently.



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



to see all the available options for JPEG save.
Write this image to a memory buffer . Save options may be encoded in the format_string or given as a hash . For example . or equivalently . The full set of save options depend on the selected saver . Try something like . to see all the available options for JPEG save .
def write_to_buffer format_string, **opts
      raise Vips::Error, "filename is nil" if format_string.nil?
      filename = Vips.p2str(Vips.vips_filename_get_filename(format_string))
      option_string = Vips.p2str(Vips.vips_filename_get_options(format_string))
      saver = nil
      if Vips.at_least_libvips?(8, 9)
        Vips.vips_error_freeze
        saver = Vips.vips_foreign_find_save_target filename
        Vips.vips_error_thaw
      end
      if !saver.nil?
        target = Vips::Target.new_to_memory
        Vips::Operation.call saver, [self, target], opts, option_string
        buffer = target.get("blob")
      else
        saver = Vips.vips_foreign_find_save_buffer filename
        raise Vips::Error if saver.nil?
        buffer = Vips::Operation.call saver, [self], opts, option_string
        raise Vips::Error if buffer.nil?
      end
      write_gc
      buffer
    end
def write_to_buffer format_string , ** opts raise Vips :: Error , "filename is nil" if format_string . nil? filename = Vips . p2str ( Vips . vips_filename_get_filename ( format_string ) ) option_string = Vips . p2str ( Vips . vips_filename_get_options ( format_string ) ) saver = nil if Vips . at_least_libvips? ( 8 , 9 ) Vips . vips_error_freeze saver = Vips . vips_foreign_find_save_target filename Vips . vips_error_thaw end if ! saver . nil? target = Vips :: Target . new_to_memory Vips :: Operation . call saver , [ self , target ] , opts , option_string buffer = target . get ( "blob" ) else saver = Vips . vips_foreign_find_save_buffer filename raise Vips :: Error if saver . nil? buffer = Vips :: Operation . call saver , [ self ] , opts , option_string raise Vips :: Error if buffer . nil? end write_gc buffer end
Write this image to a memory buffer.
Write this image to a memory buffer .
# try to save with the new target API first, only fall back to the old # buffer API if there's no target save for this filetype
the image saved in the specified format
the image saved in the specified format
String
format_string
save format plus options
save format plus options
opts
macro
None