Class: Axon::Fit
- Inherits:
-
Object
show all
- Includes:
- Image, Enumerable
- Defined in:
- lib/axon/fit.rb
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(source, width, height) ⇒ Fit
Returns a new instance of Fit.
6
7
8
|
# File 'lib/axon/fit.rb', line 6
def initialize(source, width, height)
@source, @fit_width, @fit_height = source, width, height
end
|
Instance Method Details
#color_model ⇒ Object
14
15
16
|
# File 'lib/axon/fit.rb', line 14
def color_model
@source.color_model
end
|
#components ⇒ Object
10
11
12
|
# File 'lib/axon/fit.rb', line 10
def components
@source.components
end
|
#each ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/axon/fit.rb', line 26
def each
r = calc_fit_ratio
if r > 1
scaler = NearestNeighborScaler.new(@source, r)
scaler.each{ |*a| yield(*a) }
elsif r < 1
if r <= 0.5 && @source.kind_of?(JPEGReader)
@source.scale_denom = calc_jpeg_pre_shrink(r)
r = calc_fit_ratio
end
scaler = BilinearScaler.new(@source, r)
scaler.each{ |*a| yield(*a) }
else
@source.each{ |*a| yield(*a) }
end
end
|
#height ⇒ Object
22
23
24
|
# File 'lib/axon/fit.rb', line 22
def height
@source.height * calc_fit_ratio
end
|
#width ⇒ Object
18
19
20
|
# File 'lib/axon/fit.rb', line 18
def width
@source.width * calc_fit_ratio
end
|