Class: Axon::Fit
- Inherits:
-
Object
- Object
- Axon::Fit
- Defined in:
- lib/axon/fit.rb
Overview
Instance Method Summary collapse
-
#components ⇒ Object
Gets the components in the fitted image.
-
#gets ⇒ Object
Gets the next scanline from the fitted image.
-
#height ⇒ Object
Gets the height of the fitted image.
-
#initialize(source, width, height) ⇒ Fit
constructor
:call-seq: Fit.new(image_in, width, height).
-
#lineno ⇒ Object
Gets the index of the next line that will be fetched by gets, starting at 0.
-
#width ⇒ Object
Gets the width of the fitted image.
Constructor Details
#initialize(source, width, height) ⇒ Fit
:call-seq:
Fit.new(image_in, width, height)
Fits image_in in the box dimensions given by width and height. The resulting image will not extend beyond the given width or the given height. The resulting image will maintain the aspect ratio of image_in so the resulting image may not completely fill width and height.
The resulting image will match either width or height.
28 29 30 31 32 |
# File 'lib/axon/fit.rb', line 28 def initialize(source, width, height) @source, @fit_width, @fit_height = source, width, height @aspect_ratio = width / height.to_f @scaler = nil end |
Instance Method Details
#components ⇒ Object
Gets the components in the fitted image. Same as the components of the source image.
37 38 39 |
# File 'lib/axon/fit.rb', line 37 def components @source.components end |
#gets ⇒ Object
Gets the next scanline from the fitted image.
63 64 65 66 |
# File 'lib/axon/fit.rb', line 63 def gets @scaler ||= get_scaler @scaler.gets end |
#height ⇒ Object
Gets the height of the fitted image. This will be the given height or less.
50 51 52 |
# File 'lib/axon/fit.rb', line 50 def height @scaler ? @scaler.height : (@source.height * calc_fit_ratio).to_i end |
#lineno ⇒ Object
Gets the index of the next line that will be fetched by gets, starting at 0.
57 58 59 |
# File 'lib/axon/fit.rb', line 57 def lineno @scaler ? @scaler.lineno : 0 end |
#width ⇒ Object
Gets the width of the fitted image. This will be the given width or less.
43 44 45 |
# File 'lib/axon/fit.rb', line 43 def width @scaler ? @scaler.width : (@source.width * calc_fit_ratio).to_i end |