usr bin ruby require RMagick -------------------- --------------------

 1
 2
 3
 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/ruby
require 'RMagick'
# ---------------------------------------------------------------------
# Rect Maker Class
# ---------------------------------------------------------------------
class RectThumb
def RectThumb.make(fileIn,fileOut)
img = Magick::Image.read(fileIn).first
img.crop_resized!(150,150, Magick::CenterGravity)
begin
img.write(fileOut) { self.quality = 90 }
rescue Magick::ImageMagickError
return false
end
if FileTest.exists?(fileOut)
return true
else
return false
end
end
end
# ---------------------------------------------------------------------
# Usage: ./thumb_rect.rb [/path/to/image] [/path/to/new/image.jpeg]
# ---------------------------------------------------------------------
if ARGV[0] && ARGV[1]
fileIn = ARGV[0]
fileOut = ARGV[1]
if FileTest.exists?(fileIn)
if RectThumb.make(fileIn,fileOut) then
puts 1
exit
else
puts 0
exit
end
end
else
puts 0
end