lib/image_mosaic/image/parent.rb in image_mosaic-0.1.2 vs lib/image_mosaic/image/parent.rb in image_mosaic-0.1.3

- old
+ new

@@ -1,37 +1,29 @@ module ImageMosaic module Image #Takes an array of images and metrics and then returns a single image of composited images. class Parent - def initialize(items, colour:, columns:, dimension:) + def initialize(items, colour:, width:) @items = items @colour = colour - @columns = columns - @dimension = dimension + @width = width end def create - image.run_command(:convert, '-size', "#{WIDTH}x#{HEIGHT}", "xc:#{@colour}", image.path) - y = 0 - sliced_grid.each do |row| - x = 0 - row.each do |cell| - @image = add_image(cell, x, y) - x += @dimension - end - y += @dimension - end + image.run_command(:convert, '-size', dimensions, "xc:#{@colour}", image.path) + @items.each { |item| @image = add_image(item) } Mosaic.new(image) end private - def sliced_grid - @items.each_slice(@columns).to_a + def dimensions + # Parent image is always square for time being. + "#{@width}x#{@width}" end - def add_image(child_image, x, y) - Operations::Compositor.new(@image, child_image).save(x, y, type: 'Over', dimension: @dimension) + def add_image(image) + Operations::Compositor.new(@image, image).save end def temp_file @temp_file ||= Tempfile.new(['image_mosaic', '.png']) end