Method: Vips::Image.new_from_file

Defined in:
lib/vips8/image.rb

.new_from_file(name, opts = {}) ⇒ Image

Return a new Vips::Image for a file on disc. This method can load images in any format supported by vips. The filename can include load options, for example:

image = Vips::new_from_file "fred.jpg[shrink=2]"

You can also supply options as a hash, for example:

image = Vips::new_from_file "fred.jpg", :shrink => 2

The full set of options available depend upon the load operation that will be executed. Try something like:

$ vips jpegload

at the command-line to see a summary of the available options.

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:

  • name (String)

    the filename to load from

  • 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

[View source]

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/vips8/image.rb', line 418

def self.new_from_file(name, opts = {})
    # very common, and Vips::filename_get_filename will segv if we pass
    # this
    if name == nil
        raise Error, "filename is nil"
    end
    filename = Vips::filename_get_filename name
    option_string = Vips::filename_get_options name
    loader = Vips::Foreign.find_load filename
    if loader == nil
        raise Vips::Error
    end

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