Class: Rabbit::ImageManipulable::Base
- Inherits:
-
Object
- Object
- Rabbit::ImageManipulable::Base
show all
- Extended by:
- ModuleLoader
- Defined in:
- lib/rabbit/image/base.rb
Constant Summary
ModuleLoader::LOADERS
Instance Attribute Summary collapse
Instance Method Summary
collapse
extend_object, find_loader, loaders, push_loader, unshift_loader
Constructor Details
#initialize(filename, props) ⇒ Base
Returns a new instance of Base.
13
14
15
16
17
18
19
|
# File 'lib/rabbit/image/base.rb', line 13
def initialize(filename, props)
@filename = filename
@props = normalize_props(props)
update_size
@original_width = @width
@original_height = @height
end
|
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
11
12
13
|
# File 'lib/rabbit/image/base.rb', line 11
def height
@height
end
|
#original_height ⇒ Object
Returns the value of attribute original_height.
11
12
13
|
# File 'lib/rabbit/image/base.rb', line 11
def original_height
@original_height
end
|
#original_width ⇒ Object
Returns the value of attribute original_width.
11
12
13
|
# File 'lib/rabbit/image/base.rb', line 11
def original_width
@original_width
end
|
#width ⇒ Object
Returns the value of attribute width.
11
12
13
|
# File 'lib/rabbit/image/base.rb', line 11
def width
@width
end
|
Instance Method Details
#[](key) ⇒ Object
21
22
23
|
# File 'lib/rabbit/image/base.rb', line 21
def [](key)
@props[normalize_prop_key(key)]
end
|
#[]=(key, value) ⇒ Object
25
26
27
|
# File 'lib/rabbit/image/base.rb', line 25
def []=(key, value)
@props[normalize_prop_key(key)] = value
end
|
#draw(canvas, x, y, params = {}) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/rabbit/image/base.rb', line 62
def draw(canvas, x, y, params={})
default_params = {
:width => width,
:height => height,
}
canvas.draw_pixbuf(pixbuf, x, y, default_params.merge(params))
end
|
#keep_ratio ⇒ Object
29
30
31
|
# File 'lib/rabbit/image/base.rb', line 29
def keep_ratio
self["keep_ratio"]
end
|
#keep_ratio=(value) ⇒ Object
33
34
35
|
# File 'lib/rabbit/image/base.rb', line 33
def keep_ratio=(value)
self["keep_ratio"] = value
end
|
#pixbuf ⇒ Object
37
38
39
|
# File 'lib/rabbit/image/base.rb', line 37
def pixbuf
@pixbuf
end
|
#resize(w, h) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/rabbit/image/base.rb', line 41
def resize(w, h)
if w.nil? and h.nil?
return
elsif keep_ratio
if w and h.nil?
h = (original_height * w.to_f / original_width).ceil
elsif w.nil? and h
w = (original_width * h.to_f / original_height).ceil
end
else
w ||= width
h ||= height
end
w = w.ceil if w
h = h.ceil if h
if w and w > 0 and h and h > 0 and [w, h] != [width, height]
@width = w
@height = h
end
end
|