Class: DragonflyLibvips::Processors::ExtractArea

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly_libvips/processors/extract_area.rb

Instance Method Summary collapse

Instance Method Details

#call(content, x, y, width, height, options = {}) ⇒ Object

Raises:



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dragonfly_libvips/processors/extract_area.rb', line 4

def call(content, x, y, width, height, options = {})
  raise UnsupportedFormat unless content.ext
  raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)

  options = options.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v } # stringify keys
  format = options.fetch('format', content.ext)

  input_options = options.fetch('input_options', {})
  output_options = options.fetch('output_options', {})

  # input_options['access'] ||= 'sequential'
  if content.mime_type == 'image/jpeg'
    input_options['autorotate'] = true unless input_options.has_key?('autorotate')
  end
  output_options['profile'] ||= EPROFILE_PATH

  require 'vips'
  img = ::Vips::Image.new_from_file(content.path, input_options)

  img = img.extract_area(x, y, width, height)

  content.update(
    img.write_to_buffer(".#{format}", output_options),
    'name' => "temp.#{format}",
    'format' => format
  )
  content.ext = format
end

#update_url(url_attributes, _, _, _, _, options = {}) ⇒ Object



33
34
35
36
37
# File 'lib/dragonfly_libvips/processors/extract_area.rb', line 33

def update_url(url_attributes, _, _, _, _, options = {})
  options = options.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v } # stringify keys
  return unless format = options.fetch('format', nil)
  url_attributes.ext = format
end