Class: Morandi::Crop

Inherits:
ImageOp show all
Defined in:
lib/morandi/image-ops.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ImageOp

new_from_hash, #priority

Constructor Details

#initialize(area = nil) ⇒ Crop

Returns a new instance of Crop.



23
24
25
26
# File 'lib/morandi/image-ops.rb', line 23

def initialize(area=nil)
  super()
  @area = area
end

Instance Attribute Details

#areaObject

Returns the value of attribute area.



22
23
24
# File 'lib/morandi/image-ops.rb', line 22

def area
  @area
end

Instance Method Details

#call(image, pixbuf) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/morandi/image-ops.rb', line 36

def call(image, pixbuf)
  if @area and (not @area.width.zero?) and (not @area.height.zero?)
    # NB: Cheap - fast & shares memory
    Gdk::Pixbuf.new(pixbuf, @area.x, @area.y,
        @area.width, @area.height)
  else
    pixbuf
  end
end

#constrain(val, min, max) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/morandi/image-ops.rb', line 27

def constrain(val,min,max)
  if val < min
    min
  elsif val > max
    max
  else
    val
  end
end