Class: Axon::Cropper

Inherits:
Object
  • Object
show all
Includes:
Image, Enumerable
Defined in:
lib/axon/cropper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Image

#crop, #fit, #scale_bilinear, #scale_nearest_neighbor, #to_jpeg, #to_png, #write_jpeg, #write_png

Constructor Details

#initialize(image, width, height, x_offset = nil, y_offset = nil) ⇒ Cropper

Returns a new instance of Cropper.



8
9
10
11
12
13
14
15
16
# File 'lib/axon/cropper.rb', line 8

def initialize(image, width, height, x_offset=nil, y_offset=nil)
  @image = image
  @width = width
  @height = height
  @x_offset = x_offset || 0
  @y_offset = y_offset || 0
  @components = image.components
  @color_model = image.color_model
end

Instance Attribute Details

#color_modelObject (readonly)

Returns the value of attribute color_model.



6
7
8
# File 'lib/axon/cropper.rb', line 6

def color_model
  @color_model
end

#componentsObject (readonly)

Returns the value of attribute components.



6
7
8
# File 'lib/axon/cropper.rb', line 6

def components
  @components
end

#heightObject (readonly)

Returns the value of attribute height.



6
7
8
# File 'lib/axon/cropper.rb', line 6

def height
  @height
end

#imageObject (readonly)

Returns the value of attribute image.



6
7
8
# File 'lib/axon/cropper.rb', line 6

def image
  @image
end

#widthObject (readonly)

Returns the value of attribute width.



6
7
8
# File 'lib/axon/cropper.rb', line 6

def width
  @width
end

Instance Method Details

#eachObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/axon/cropper.rb', line 18

def each
  sl_width = @width * @components
  sl_offset = @x_offset * @components

  @image.each_with_index do |orig_sl, i|
    next if i < @y_offset
    yield orig_sl[sl_offset, sl_width]
    break if i == @height - 1
  end
end