Class: Axon::Fit

Inherits:
Object
  • Object
show all
Defined in:
lib/axon/fit.rb

Overview

An Image Box Scaler

Axon::Fit will scale images to fit inside given box dimensions while maintaining the aspect ratio.

Example

image_in = Axon::Solid.new(10, 20)
f = Axon::Fit.new(image_in, 5, 20)
f.width  # => 5
f.height # => 10

Instance Method Summary collapse

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
# File 'lib/axon/fit.rb', line 28

def initialize(source, width, height)
  @source, @fit_width, @fit_height = source, width, height
  @scaler = nil
end

Instance Method Details

#color_modelObject

Gets the color model of the fitted image. Same as the color model of the source image.



43
44
45
# File 'lib/axon/fit.rb', line 43

def color_model
  @source.color_model
end

#componentsObject

Gets the components in the fitted image. Same as the components of the source image.



36
37
38
# File 'lib/axon/fit.rb', line 36

def components
  @source.components
end

#getsObject

Gets the next scanline from the fitted image.



69
70
71
72
# File 'lib/axon/fit.rb', line 69

def gets
  @scaler ||= get_scaler
  @scaler.gets
end

#heightObject

Gets the height of the fitted image. This will be the given height or less.



56
57
58
# File 'lib/axon/fit.rb', line 56

def height
  @scaler ? @scaler.height : calculate_height
end

#linenoObject

Gets the index of the next line that will be fetched by gets, starting at 0.



63
64
65
# File 'lib/axon/fit.rb', line 63

def lineno
  @scaler ? @scaler.lineno : 0
end

#widthObject

Gets the width of the fitted image. This will be the given width or less.



49
50
51
# File 'lib/axon/fit.rb', line 49

def width
  @scaler ? @scaler.width : calculate_width
end