Class: FlickrbCollage::Collage

Inherits:
Object
  • Object
show all
Defined in:
lib/flickrb_collage/collage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#canvasObject (readonly)

Returns the value of attribute canvas.



6
7
8
# File 'lib/flickrb_collage/collage.rb', line 6

def canvas
  @canvas
end

#image_pathsObject (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

#layoutObject (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

#buildObject



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