Class: CompositorNode::Resizer

Inherits:
Object
  • Object
show all
Defined in:
lib/compositor_node/resizer.rb

Defined Under Namespace

Classes: MissingDimensionResizeError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Resizer

Returns a new instance of Resizer.



7
8
9
10
11
# File 'lib/compositor_node/resizer.rb', line 7

def initialize(options = {})
  @source = options[:source]
  @width = options[:width]
  @height = options[:height]
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



3
4
5
# File 'lib/compositor_node/resizer.rb', line 3

def height
  @height
end

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/compositor_node/resizer.rb', line 3

def source
  @source
end

#widthObject

Returns the value of attribute width.



3
4
5
# File 'lib/compositor_node/resizer.rb', line 3

def width
  @width
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/compositor_node/resizer.rb', line 13

def execute
  raise MissingDimensionResizeError unless @width || @height
  source = @source.execute
 
  unless @width && @height
    original_width = Engine.width(source)
    original_height = Engine.height(source)

    if @width
      ratio = original_width / @width.to_f
      @height = original_height / ratio
    elsif @height
      ratio = original_height / @height.to_f
      @width = original_width / ratio
    end
  end

  Engine.resize(source, @width, @height)
end