Class: FeaturedImage::Converter
- Inherits:
-
Object
- Object
- FeaturedImage::Converter
- Defined in:
- lib/featuredimage/converter.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #convert(image) ⇒ Object
-
#initialize(width, height, opts = {}) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(width, height, opts = {}) ⇒ Converter
Returns a new instance of Converter.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/featuredimage/converter.rb', line 16 def initialize(width, height, opts = {}) @width, @height = width, height # default convert options @opts = { :format => "JPG", :quality => 60 } @opts.merge!(opts) end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
9 10 11 |
# File 'lib/featuredimage/converter.rb', line 9 def height @height end |
#opts ⇒ Object
Returns the value of attribute opts.
9 10 11 |
# File 'lib/featuredimage/converter.rb', line 9 def opts @opts end |
#width ⇒ Object
Returns the value of attribute width.
9 10 11 |
# File 'lib/featuredimage/converter.rb', line 9 def width @width end |
Class Method Details
Instance Method Details
#convert(image) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/featuredimage/converter.rb', line 27 def convert(image) target_size = {w:@width, h:@height} original_size = {w:image.columns, h:image.rows} resized_size = get_resized_size(original_size, target_size) resized_image = image.resize(resized_size[:w], resized_size[:h]) offset = get_offset(target_size, resized_size) cropped_image = resized_image.crop(offset[:x], offset[:y], target_size[:w], target_size[:h]) image_to_blob(cropped_image) end |