module ImageProcessing::Vips::Processor::Utils

Public Instance Methods

select_valid_loader_options(source_path, options) click to toggle source

libvips uses various loaders depending on the input format.

# File lib/image_processing/vips.rb, line 180
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) click to toggle source

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 some introspection and filter out options that don’t exist for a particular loader or saver.

# File lib/image_processing/vips.rb, line 197
def select_valid_options(operation_name, options)
  introspect        = ::Vips::Introspect.get(operation_name)
  operation_options = introspect.optional_input.keys.map(&:to_sym)

  options.select { |name, value| operation_options.include?(name) }
end
select_valid_saver_options(destination_path, options) click to toggle source

Filters out unknown options for saving images.

# File lib/image_processing/vips.rb, line 186
def select_valid_saver_options(destination_path, options)
  saver = ::Vips.vips_foreign_find_save(destination_path)
  saver ? select_valid_options(saver, options) : options
end