Class: CompositorNode::Resizer
- Inherits:
-
Object
- Object
- CompositorNode::Resizer
- Defined in:
- lib/compositor_node/resizer.rb
Defined Under Namespace
Classes: MissingDimensionResizeError
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#source ⇒ Object
Returns the value of attribute source.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(options = {}) ⇒ Resizer
constructor
A new instance of Resizer.
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( = {}) @source = [:source] @width = [:width] @height = [:height] end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/compositor_node/resizer.rb', line 3 def height @height end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/compositor_node/resizer.rb', line 3 def source @source end |
#width ⇒ Object
Returns the value of attribute width.
3 4 5 |
# File 'lib/compositor_node/resizer.rb', line 3 def width @width end |
Instance Method Details
#execute ⇒ Object
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 |