Class: Rabbit::ImageManipulable::Base

Inherits:
Object
  • Object
show all
Extended by:
ModuleLoader
Defined in:
lib/rabbit/image/base.rb

Direct Known Subclasses

Default, Dia, EPS, GIMP, PDF, SVG

Constant Summary

Constants included from ModuleLoader

ModuleLoader::LOADERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ModuleLoader

extend_object, find_loader, loaders, push_loader, unshift_loader

Constructor Details

#initialize(filename, props) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
19
20
# File 'lib/rabbit/image/base.rb', line 14

def initialize(filename, props)
  @filename = filename
  @props = normalize_props(props)
  update_size
  @original_width = @width
  @original_height = @height
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



12
13
14
# File 'lib/rabbit/image/base.rb', line 12

def height
  @height
end

#original_heightObject (readonly)

Returns the value of attribute original_height.



12
13
14
# File 'lib/rabbit/image/base.rb', line 12

def original_height
  @original_height
end

#original_widthObject (readonly)

Returns the value of attribute original_width.



12
13
14
# File 'lib/rabbit/image/base.rb', line 12

def original_width
  @original_width
end

#widthObject (readonly)

Returns the value of attribute width.



12
13
14
# File 'lib/rabbit/image/base.rb', line 12

def width
  @width
end

Instance Method Details

#[](key) ⇒ Object



22
23
24
# File 'lib/rabbit/image/base.rb', line 22

def [](key)
  @props[normalize_prop_key(key)]
end

#[]=(key, value) ⇒ Object



26
27
28
# File 'lib/rabbit/image/base.rb', line 26

def []=(key, value)
  @props[normalize_prop_key(key)] = value
end

#draw(canvas, x, y, params = {}) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/rabbit/image/base.rb', line 63

def draw(canvas, x, y, params={})
  default_params = {
    :width => width,
    :height => height,
  }
  canvas.draw_pixbuf(pixbuf, x, y, default_params.merge(params))
end

#keep_ratioObject



30
31
32
# File 'lib/rabbit/image/base.rb', line 30

def keep_ratio
  self["keep_ratio"]
end

#keep_ratio=(value) ⇒ Object



34
35
36
# File 'lib/rabbit/image/base.rb', line 34

def keep_ratio=(value)
  self["keep_ratio"] = value
end

#pixbufObject



38
39
40
# File 'lib/rabbit/image/base.rb', line 38

def pixbuf
  @pixbuf
end

#resize(w, h) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rabbit/image/base.rb', line 42

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