Class: ImageProcessing::Vips::Pipeline

Inherits:
Object
  • Object
show all
Includes:
Chainable
Defined in:
lib/image_processing/vips/pipeline.rb

Instance Method Summary collapse

Methods included from Chainable

#branch, #call, #convert, #custom, #default_options, #loader, #method_missing, #operation, #saver, #source

Constructor Details

#initialize(options) ⇒ Pipeline

Returns a new instance of Pipeline.



6
7
8
# File 'lib/image_processing/vips/pipeline.rb', line 6

def initialize(options)
  @default_options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ImageProcessing::Vips::Chainable

Instance Method Details

#call!(save: true) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/image_processing/vips/pipeline.rb', line 10

def call!(save: true)
  processor = Processor.new(default_options[:source])
  image     = processor.load_image(default_options[:loader])

  default_options[:operations].each do |name, args|
    if name == :custom
      image = args.first.call(image)
    else
      image = processor.apply_operation(name, image, *args)
    end
  end

  if save
    processor.save_image(image, default_options[:format], default_options[:saver])
  else
    image
  end
end