Class: ImageResizing::ImageResizer

Inherits:
Object
  • Object
show all
Defined in:
lib/image_resizing.rb

Instance Method Summary collapse

Constructor Details

#initializeImageResizer

Returns a new instance of ImageResizer.



8
9
# File 'lib/image_resizing.rb', line 8

def initialize
end

Instance Method Details

#resize_by_ratio(ratio_in_percent, input_file, output_file) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/image_resizing.rb', line 25

def resize_by_ratio(ratio_in_percent, input_file, output_file)
  throw_exception_when_input_and_out_files_are_not_given input_file, output_file

  ratio = ratio_in_percent.to_f / 100.to_f

  begin
    image = Magick::Image.read(input_file).first
    resized_image = image.resize(ratio)
    resized_image.write(output_file)
  rescue Exception => e
    raise RuntimeError, e.message
  end

  true
end

#resize_by_width_and_height(width, height, input_file, output_file) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/image_resizing.rb', line 11

def resize_by_width_and_height(width, height, input_file, output_file)
  throw_exception_when_input_and_out_files_are_not_given input_file, output_file

  begin
    image = Magick::Image.read(input_file).first
    resized_image = image.resize(width, height)
    resized_image.write(output_file)
  rescue Exception => e
    raise RuntimeError, e.message
  end

  true
end