Class: RackResize::Processors::Imlib2

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_resize/processors/imlib2.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
# File 'lib/rack_resize/processors/imlib2.rb', line 9

def resize(source_file:, target_file:, target_width:, target_height:)
  image = Rszr::Image.load(source_file)
  image.resize!(target_width || :auto, target_height || :auto) if target_width || target_height

  if target_file
    image.call(destination: target_file)
    image.save(target_file)
  else
    image.save_data(format: source_file.to_s =~ /\.png$/ ? :png : :jpeg)
  end
end