class RemoveBg::RequestOptions

Options for image processing requests. Arbitary options are passed directly to the API.

Constants

CHANNELS_ALPHA
CHANNELS_RGBA
FOREGROUND_TYPE_AUTO
FOREGROUND_TYPE_PERSON
FOREGROUND_TYPE_PRODUCT
FORMAT_JPG
FORMAT_PNG
FORMAT_ZIP
SIZE_4K
SIZE_AUTO
SIZE_HD
SIZE_MEDIUM
SIZE_REGULAR

Public Class Methods

new(raw_options = {}) click to toggle source
Calls superclass method RemoveBg::BaseRequestOptions::new
# File lib/remove_bg/request_options.rb, line 24
def initialize(raw_options = {})
  options = raw_options.dup
  options[:size] ||= SIZE_AUTO

  if options.key?(:format)
    options[:format] = optimize_format(options[:format])
  end

  super(options)
end

Private Instance Methods

can_process_images?() click to toggle source
# File lib/remove_bg/request_options.rb, line 48
def can_process_images?
  RemoveBg::Configuration.configuration.can_process_images?
end
optimization_enabled?() click to toggle source
# File lib/remove_bg/request_options.rb, line 52
def optimization_enabled?
  RemoveBg::Configuration.configuration.auto_upgrade_png_to_zip
end
optimize_format(requested_format) click to toggle source

Save bandwidth where possible

# File lib/remove_bg/request_options.rb, line 38
def optimize_format(requested_format)
  requested_png = requested_format.to_s.casecmp?(FORMAT_PNG)

  if requested_png && optimization_enabled? && can_process_images?
    FORMAT_ZIP
  else
    requested_format
  end
end