Module: ImageProcessing::Vips::Processor::Utils

Defined in:
lib/image_processing/vips.rb

Class Method Summary collapse

Class Method Details

.select_valid_loader_options(source_path, options) ⇒ Object

libvips uses various loaders depending on the input format.



175
176
177
178
# File 'lib/image_processing/vips.rb', line 175

def select_valid_loader_options(source_path, options)
  loader = ::Vips.vips_foreign_find_load(source_path)
  loader ? select_valid_options(loader, options) : options
end

.select_valid_options(operation_name, options) ⇒ Object

libvips uses various loaders and savers depending on the input and output image format. Each of these loaders and savers accept slightly different options, so to allow the user to be able to specify options for a specific loader/saver and have it ignored for other loaders/savers, we do a little bit of introspection and filter out options that don’t exist for a particular loader or saver.



192
193
194
195
196
197
198
199
200
201
# File 'lib/image_processing/vips.rb', line 192

def select_valid_options(operation_name, options)
  operation = ::Vips::Operation.new(operation_name)

  operation_options = operation.get_construct_args
    .select { |name, flags| (flags & ::Vips::ARGUMENT_INPUT)    != 0 }
    .select { |name, flags| (flags & ::Vips::ARGUMENT_REQUIRED) == 0 }
    .map(&:first).map(&:to_sym)

  options.select { |name, value| operation_options.include?(name) }
end

.select_valid_saver_options(destination_path, options) ⇒ Object

Filters out unknown options for saving images.



181
182
183
184
# File 'lib/image_processing/vips.rb', line 181

def select_valid_saver_options(destination_path, options)
  saver = ::Vips.vips_foreign_find_save(destination_path)
  saver ? select_valid_options(saver, options) : options
end