image_mosaic 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72c39930b3c7187b496a4a57b615adbd3d6d2b2f
4
- data.tar.gz: 6aa80f9493ef2c604ca68d3a0dc2a2431fd09d1b
3
+ metadata.gz: 4a1a7071ef66b370eb317cb4253fc2a27f1dabe6
4
+ data.tar.gz: 44e791111586332891ef202a18cc3995b25cee15
5
5
  SHA512:
6
- metadata.gz: fa1d1015f6e43dcb13da577b34663215a74ff3baeb9854641fa17d81f2d452c9832f2180f0925e05366dd38b91eea7d9233d138dc5a9ff300f575930ca18ae50
7
- data.tar.gz: 7b6d020d22948a5e84e72c3523debdcf7dd321c74ba581f2cdea33f1a64be8b4bccf8f5160ff0da868d498dbf70941611b7227dc314704d206de7e4e40c4e5d1
6
+ metadata.gz: 281facb0beed13789225c0463cdc90257d144d2fb3634140d5c04152ca84fe016c5e12bc72dc9fe2555696d97eff0cc8bf032407077f2e6e5b26b84afcdca69d
7
+ data.tar.gz: 3a924e0c83cb1d5e124226abec8e5da90d5e24a07b7e39f7f64f946fc45d39520527e08ec15a2481b9145fbec7494eefb17d7164897e493e0e6d8262f6af8b1a
data/lib/image_mosaic.rb CHANGED
@@ -3,11 +3,15 @@ require 'mini_magick'
3
3
  require 'tempfile'
4
4
  require 'securerandom'
5
5
  require 'image_mosaic/operations/compositor'
6
+ require 'image_mosaic/data/setting'
6
7
  require 'image_mosaic/data/validator'
7
8
  require 'image_mosaic/image/parent'
8
9
  require 'image_mosaic/image/child'
9
10
 
10
11
  module ImageMosaic
12
+ HEIGHT = 1000
13
+ WIDTH = 1000
14
+
11
15
  class Construct
12
16
  def initialize(items)
13
17
  @items = items
@@ -20,7 +24,11 @@ module ImageMosaic
20
24
  private
21
25
 
22
26
  def parent
23
- @parent ||= Image::Parent.new(valid_items).create
27
+ @parent ||= Image::Parent.new(valid_items, colour: 'white', columns: setting.columns, dimension: setting.dimension).create
28
+ end
29
+
30
+ def setting
31
+ @setting ||= Data::Setting.new(valid_items.count)
24
32
  end
25
33
 
26
34
  def valid_items
@@ -0,0 +1,18 @@
1
+ module ImageMosaic
2
+ module Data
3
+ class Setting
4
+ def initialize(count, width: WIDTH)
5
+ @count = count
6
+ @width = width
7
+ end
8
+
9
+ def columns
10
+ Math.sqrt(@count).ceil
11
+ end
12
+
13
+ def dimension
14
+ @width / columns
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,26 +1,24 @@
1
1
  module ImageMosaic
2
2
  module Image
3
- #Takes an array of images and metrics and then returns a single image of compisited images.
3
+ #Takes an array of images and metrics and then returns a single image of composited images.
4
4
  class Parent
5
- def initialize(items, width: 1000, height: 1000, colour: 'white', columns: 5, cell_dimension: 200)
5
+ def initialize(items, colour: 'white', columns: 5, dimension: 200)
6
6
  @items = items
7
- @width = width
8
- @height = height
9
7
  @colour = colour
10
8
  @columns = columns
11
- @cell_dimension = cell_dimension
9
+ @dimension = dimension
12
10
  end
13
11
 
14
12
  def create
15
- image.run_command(:convert, '-size', "#{@width}x#{@height}", "xc:#{@colour}", image.path)
13
+ image.run_command(:convert, '-size', "#{WIDTH}x#{HEIGHT}", "xc:#{@colour}", image.path)
16
14
  y = 0
17
15
  sliced_grid.each do |row|
18
16
  x = 0
19
17
  row.each do |cell|
20
18
  @image = add_image(cell, x, y)
21
- x += @cell_dimension
19
+ x += @dimension
22
20
  end
23
- y += @cell_dimension
21
+ y += @dimension
24
22
  end
25
23
  image
26
24
  end
@@ -32,7 +30,7 @@ module ImageMosaic
32
30
  end
33
31
 
34
32
  def add_image(child_image, x, y)
35
- Operations::Compositor.new(@image, child_image).save(x, y, type: 'Over', dimension: @cell_dimension)
33
+ Operations::Compositor.new(@image, child_image).save(x, y, type: 'Over', dimension: @dimension)
36
34
  end
37
35
 
38
36
  def temp_file
@@ -1,3 +1,3 @@
1
1
  module ImageMosaic
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_mosaic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Goodwin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-25 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,6 +85,7 @@ files:
85
85
  - bin/setup
86
86
  - image_mosaic.gemspec
87
87
  - lib/image_mosaic.rb
88
+ - lib/image_mosaic/data/setting.rb
88
89
  - lib/image_mosaic/data/validator.rb
89
90
  - lib/image_mosaic/image/child.rb
90
91
  - lib/image_mosaic/image/parent.rb