Class: Shrine::Plugins::Blurhash::PixelsExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/shrine/plugins/blurhash.rb

Constant Summary collapse

SUPPORTED_EXTRACTORS =
[:ruby_vips].freeze

Instance Method Summary collapse

Constructor Details

#initialize(tool, on_error: method(:fail)) ⇒ PixelsExtractor

Returns a new instance of PixelsExtractor.



109
110
111
112
113
114
115
116
# File 'lib/shrine/plugins/blurhash.rb', line 109

def initialize(tool, on_error: method(:fail))
  unless SUPPORTED_EXTRACTORS.include?(tool)
    raise Error, "unknown pixel extractor #{tool.inspect}, supported extractors are: #{SUPPORTED_EXTRACTORS.join(',')}"
  end

  @tool     = tool
  @on_error = on_error
end

Instance Method Details

#call(io, resize_to) ⇒ Object



118
119
120
121
122
# File 'lib/shrine/plugins/blurhash.rb', line 118

def call(io, resize_to)
  dimensions = send(:"extract_with_#{@tool}", io, resize_to)
  io.rewind
  dimensions
end