Class: Vips::Source

Inherits:
Connection show all
Defined in:
lib/vips/source.rb

Overview

A source. For example:

source = Vips::Source.new_from_file("k2.jpg")
image = Vips::Image.new_from_source(source)

Direct Known Subclasses

SourceCustom

Defined Under Namespace

Modules: SourceLayout Classes: ManagedStruct, Struct

Class Method Summary collapse

Methods inherited from Connection

#filename, #nick

Methods inherited from Object

#get, #get_pspec, #get_typeof, #get_typeof_error, print_all, #set, #signal_connect

Methods inherited from GObject::GObject

ffi_managed_struct, #ffi_managed_struct, #ffi_struct, ffi_struct, #initialize

Constructor Details

This class inherits a constructor from GObject::GObject

Class Method Details

.new_from_descriptor(descriptor) ⇒ Source

Create a new source from a file descriptor. File descriptors are small integers, for example 0 is stdin.

Pass sources to Image.new_from_source to load images from them.

Parameters:

  • descriptor (Integer)

    the file descriptor

Returns:

  • (Source)

    the new Vips::Source

Raises:


48
49
50
51
52
53
# File 'lib/vips/source.rb', line 48

def self.new_from_descriptor(descriptor)
  ptr = Vips::vips_source_new_from_descriptor descriptor
  raise Vips::Error if ptr.null?

  Vips::Source.new ptr
end

.new_from_file(filename) ⇒ Source

Create a new source from a file name.

Pass sources to Image.new_from_source to load images from them.

Parameters:

  • filename (String)

    the name of the file

Returns:

  • (Source)

    the new Vips::Source

Raises:


62
63
64
65
66
67
68
# File 'lib/vips/source.rb', line 62

def self.new_from_file(filename)
  raise Vips::Error, "filename is nil" if filename.nil?
  ptr = Vips::vips_source_new_from_file filename
  raise Vips::Error if ptr.null?

  Vips::Source.new ptr
end

.new_from_memory(data) ⇒ Source

Create a new source from an area of memory. Memory areas can be strings, arrays and so forth -- anything that supports bytesize.

Pass sources to Image.new_from_source to load images from them.

Parameters:

  • data (String)

    memory area

Returns:

  • (Source)

    the new Vips::Source

Raises:


78
79
80
81
82
83
84
85
86
# File 'lib/vips/source.rb', line 78

def self.new_from_memory(data)
  ptr = Vips::vips_source_new_from_memory data, data.bytesize
  raise Vips::Error if ptr.null?

  # FIXME do we need to keep a ref to the underlying memory area? what 
  # about Image.new_from_buffer? Does that need a secret ref too?

  Vips::Source.new ptr
end