Class: Axon::Cropper
- Inherits:
-
Object
- Object
- Axon::Cropper
- Includes:
- Image, Enumerable
- Defined in:
- lib/axon/cropper.rb
Instance Attribute Summary collapse
-
#color_model ⇒ Object
readonly
Returns the value of attribute color_model.
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(image, width, height, x_offset = nil, y_offset = nil) ⇒ Cropper
constructor
A new instance of Cropper.
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_model ⇒ Object (readonly)
Returns the value of attribute color_model.
6 7 8 |
# File 'lib/axon/cropper.rb', line 6 def color_model @color_model end |
#components ⇒ Object (readonly)
Returns the value of attribute components.
6 7 8 |
# File 'lib/axon/cropper.rb', line 6 def components @components end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
6 7 8 |
# File 'lib/axon/cropper.rb', line 6 def height @height end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
6 7 8 |
# File 'lib/axon/cropper.rb', line 6 def image @image end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
6 7 8 |
# File 'lib/axon/cropper.rb', line 6 def width @width end |
Instance Method Details
#each ⇒ Object
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 |