-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.rb
61 lines (47 loc) · 1016 Bytes
/
image.rb
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'mini_magick'
class Image
def initialize(src)
@src = src
@img_obj = MiniMagick::Image.new(src)
end
def copy(filename)
save(filename)
Image.new(filename)
end
def crop(x, y, w, h)
@img_obj.crop("#{w}x#{h}+#{x}+#{y}") # WxH+X+Y
end
def crop_left
# Removes the right side of the image
w = width / 2
h = height - 1
crop(0, 0, w, h)
end
def crop_right
# Removes the left side of the image
w = width / 2
h = height - 1
crop(w, 0, w, h)
end
def landscape?
@img_obj.landscape?
end
def width
@img_obj.dimensions[0]
end
def height
@img_obj.dimensions[1]
end
def resize(w, h)
@img_obj.resize("#{w}x#{h}")
end
def rotate(degrees)
@img_obj.rotate(degrees.to_s)
end
def save(filename)
@img_obj.write(filename)
end
def save!
@img_obj.write(@src)
end
end