Class: Ii

Inherits:
Object
  • Object
show all
Defined in:
lib/ii.rb,
lib/ii/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.resize(filename, new_filename, resize_ratio) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ii.rb', line 9

def self.resize(filename, new_filename, resize_ratio)
  # read the image
  img = Magick::Image.read(filename).first

  # get the image height and width
  width = img.columns
  height = img.rows

  # calculate the dest height and width
  dest_height = height*resize_ratio
  dest_width = width*resize_ratio

  # make sure height and width is not 0
  dest_height = dest_height < 1 ? 1 : dest_height
  dest_width = dest_width < 1 ? 1:dest_width

  # resize the new image
  # the api can be found at http://studio.imagemagick.org/RMagick/doc/constants.html#GravityType
  new_img = img.resize(dest_width, dest_height, Magick::LanczosFilter, 0.8)
  new_img2 = img.

  # set quality
  new_img.write(new_filename) {self.quality = 70 }

  # clean the RAM
  img.destroy!
  new_img.destroy!
end