Method: Vips::Image#write_to_file

Defined in:
lib/vips/image.rb

#write_to_file(name, **opts) ⇒ Object

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

image.write_to_file "fred.jpg[Q=90]"

or equivalently:

image.write_to_file "fred.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.

Parameters:

  • opts (Hash)

    set of options

  • name (String)

    filename to write to

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

Raises:



595
596
597
598
599
600
601
602
603
604
605
606
# File 'lib/vips/image.rb', line 595

def write_to_file name, **opts
  raise Vips::Error, "filename is nil" if name.nil?

  filename = Vips.p2str(Vips.vips_filename_get_filename(name))
  option_string = Vips.p2str(Vips.vips_filename_get_options(name))
  saver = Vips.vips_foreign_find_save filename
  raise Vips::Error if saver.nil?

  Vips::Operation.call saver, [self, filename], opts, option_string

  write_gc
end