Class: RackResize::Processors::Vips

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_resize/processors/vips.rb

Instance Method Summary collapse

Instance Method Details

#resize(source_file:, target_file:, target_width:, target_height:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rack_resize/processors/vips.rb', line 9

def resize(source_file:, target_file:, target_width:, target_height:)
  image = ImageProcessing::Vips.source(source_file)
  image = image.resize_to_limit(target_width, target_height) if target_width || target_height
  image = image.saver(quality: RackResize.config.default_quality)

  if target_file
    image.call(destination: target_file)
  else
    begin
      tmp_file = image.call
      return tmp_file.read
    ensure
      tmp_file.unlink
    end
  end
end