Class: FlickrbCollage::Collage
- Inherits:
-
Object
- Object
- FlickrbCollage::Collage
- Defined in:
- lib/flickrb_collage/collage.rb
Instance Attribute Summary collapse
-
#canvas ⇒ Object
readonly
Returns the value of attribute canvas.
-
#image_paths ⇒ Object
readonly
Returns the value of attribute image_paths.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
Instance Method Summary collapse
- #build ⇒ Object
- #create(file_name = "#{DateTime.now.strftime('%Y%m%d%H%M%S')}.png") ⇒ Object
-
#initialize(image_paths = [], layout = CollageLayout.new) ⇒ Collage
constructor
A new instance of Collage.
Constructor Details
#initialize(image_paths = [], layout = CollageLayout.new) ⇒ Collage
Returns a new instance of Collage.
8 9 10 11 12 |
# File 'lib/flickrb_collage/collage.rb', line 8 def initialize(image_paths = [], layout = CollageLayout.new) @layout = layout @image_paths = image_paths @canvas = create_new_image end |
Instance Attribute Details
#canvas ⇒ Object (readonly)
Returns the value of attribute canvas.
6 7 8 |
# File 'lib/flickrb_collage/collage.rb', line 6 def canvas @canvas end |
#image_paths ⇒ Object (readonly)
Returns the value of attribute image_paths.
6 7 8 |
# File 'lib/flickrb_collage/collage.rb', line 6 def image_paths @image_paths end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
6 7 8 |
# File 'lib/flickrb_collage/collage.rb', line 6 def layout @layout end |
Instance Method Details
#build ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/flickrb_collage/collage.rb', line 14 def build images = image_paths.map { |p| MiniMagick::Image.open p.path } resized_images = image_paths.map.with_index do |path, index| image = MiniMagick::Image.open(path.path) image.crop(layout.crop_dimensions(index, image.width, image.height)) add_image_to_canvas(image, layout.cell_dimensions(index)) end true end |
#create(file_name = "#{DateTime.now.strftime('%Y%m%d%H%M%S')}.png") ⇒ Object
24 25 26 27 |
# File 'lib/flickrb_collage/collage.rb', line 24 def create(file_name = "#{DateTime.now.strftime('%Y%m%d%H%M%S')}.png") FileUtils.mv(canvas.path, file_name) puts "Finished collage is available at #{file_name}" end |