image_mosaic 0.1.1 → 0.1.2

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: 4a1a7071ef66b370eb317cb4253fc2a27f1dabe6
4
- data.tar.gz: 44e791111586332891ef202a18cc3995b25cee15
3
+ metadata.gz: 16c5f7ada72b064ecf1bef0bd89f7dc50dc28a28
4
+ data.tar.gz: 5da2b55388a4897099f432885488fe124601790b
5
5
  SHA512:
6
- metadata.gz: 281facb0beed13789225c0463cdc90257d144d2fb3634140d5c04152ca84fe016c5e12bc72dc9fe2555696d97eff0cc8bf032407077f2e6e5b26b84afcdca69d
7
- data.tar.gz: 3a924e0c83cb1d5e124226abec8e5da90d5e24a07b7e39f7f64f946fc45d39520527e08ec15a2481b9145fbec7494eefb17d7164897e493e0e6d8262f6af8b1a
6
+ metadata.gz: df1829264594f547382597ca356919679b6a58ba9bd605a1da517e4bb29f219ea70dd03eca958ed637525086b4b59dd378a29a6348abc6b09a1080e565873973
7
+ data.tar.gz: 240a137ef6e4c0453dcb2df2d7e607cd8160b605c47ac1ce7fdc96c307a794f0d199d7faf979b8a093481f5b07dfefabdc54e18abe24c3f694077236658bed46
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  # ImageMosaic
2
2
  [![Build Status](https://travis-ci.org/Dannyguk/image_mosaic.svg?branch=master)](https://travis-ci.org/Dannyguk/image_mosaic)
3
3
 
4
- ImageMosaic takes an array of up to 20 images and returns a collage of the images in a grid format.
5
-
6
- Each image in the collage is currently resized to 200x200 pixels. The image it returns in 1000x1000 pixels.
4
+ ImageMosaic takes an array of images and returns a collage of the images in a grid format.
7
5
 
8
6
  ## Installation
9
7
 
@@ -33,12 +31,35 @@ Or install it yourself as:
33
31
 
34
32
  ## Usage
35
33
 
36
- Create an image from an array of image URLs. The resulting image is saved to the local file system.
34
+ Create an image from an array of image URLs.
35
+
36
+ The size of each piece of the final image and the number of columns and rows will vary depending on how many images are provided.
37
+
38
+ **Note**: the final image is fixed to 1000x1000 pixels with a white background.
39
+
40
+ An instance of a `Mosaic` object is returned, calling `save` on this will save the image to the filesystem with a random name.
37
41
 
38
42
  ```ruby
39
43
  images = (0..20).map { 'https://unsplash.it/200/200?random' }
40
- mosaic = ImageMosaic::Construct.new(images)
44
+ mosaic = ImageMosaic.create(images)
41
45
  mosaic.save
46
+ mosaic.filename
47
+ => "mosaic_9ebfcb8c-b554-4748-9b2e-3d4eb7b8f2b0.png"
48
+ ```
49
+
50
+ If you want to retrieve the instance of `MiniMagick::Image` behind and manipulate it further you can.
51
+
52
+ ```ruby
53
+ images = (0..20).map { 'https://unsplash.it/200/200?random' }
54
+ mosaic = ImageMosaic.create(images)
55
+ mosaic.image
56
+ => #<MiniMagick::Image:0x007fbfb2a6b868 @path="/var/folders/7g/7wdhmvx96856frwy0jf78rsr0000gn/T/mini_magick20170426-64311-eom10b.png", @tempfile=#<Tempfile:/var/folders/7g/7wdhmvx96856frwy0jf78rsr0000gn/T/mini_magick20170426-64311-eom10b.png (closed)>, @info=#<MiniMagick::Image::Info:0x007fbfb2a6b818 @path="/var/folders/7g/7wdhmvx96856frwy0jf78rsr0000gn/T/mini_magick20170426-64311-eom10b.png", @info={}>>
57
+ ```
58
+ ### Background Colour
59
+ The default background colour is white, background colour can be specified as a valid hex code (with preceeding #). If an invalid code is provided the background will be white.
60
+
61
+ ```ruby
62
+ ImageMosaic.create(images, colour: '#00ff00')
42
63
  ```
43
64
 
44
65
  ## Contributing
@@ -0,0 +1,25 @@
1
+ module ImageMosaic
2
+ module Data
3
+ class Background
4
+ PATTERN = /^#([0-9a-fA-F]{3}){1,2}$/
5
+
6
+ def initialize(hex)
7
+ @hex = hex
8
+ end
9
+
10
+ def hex
11
+ valid? ? @hex : COLOUR
12
+ end
13
+
14
+ private
15
+
16
+ def valid?
17
+ !!match
18
+ end
19
+
20
+ def match
21
+ @hex =~ PATTERN
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ module ImageMosaic
2
+ module Image
3
+ class Mosaic
4
+ attr_reader :image
5
+
6
+ def initialize(image)
7
+ @image = image
8
+ @securerandom = SecureRandom.uuid
9
+ end
10
+
11
+ def save
12
+ @image.write(filename)
13
+ end
14
+
15
+ def filename
16
+ "mosaic_#{@securerandom}.png"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -2,7 +2,7 @@ module ImageMosaic
2
2
  module Image
3
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, colour: 'white', columns: 5, dimension: 200)
5
+ def initialize(items, colour:, columns:, dimension:)
6
6
  @items = items
7
7
  @colour = colour
8
8
  @columns = columns
@@ -20,7 +20,7 @@ module ImageMosaic
20
20
  end
21
21
  y += @dimension
22
22
  end
23
- image
23
+ Mosaic.new(image)
24
24
  end
25
25
 
26
26
  private
@@ -0,0 +1,28 @@
1
+ module ImageMosaic
2
+ module Operations
3
+ class Construct
4
+ def initialize(items, colour: COLOUR)
5
+ @items = items
6
+ @colour = colour
7
+ end
8
+
9
+ def parent
10
+ @parent ||= Image::Parent.new(valid_items, colour: @colour, columns: setting.columns, dimension: setting.dimension).create
11
+ end
12
+
13
+ private
14
+
15
+ def setting
16
+ @setting ||= Data::Setting.new(valid_items.count)
17
+ end
18
+
19
+ def valid_items
20
+ @valid_items ||= Data::Validator.new(@items).items
21
+ end
22
+
23
+ def background
24
+ @background ||= Data::Background.new(@colour).hex
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ module ImageMosaic
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module ImageMosaic
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/image_mosaic.rb CHANGED
@@ -1,38 +1,23 @@
1
- require "image_mosaic/version"
1
+ require 'image_mosaic/version'
2
2
  require 'mini_magick'
3
3
  require 'tempfile'
4
4
  require 'securerandom'
5
- require 'image_mosaic/operations/compositor'
5
+ require 'image_mosaic/data/background'
6
6
  require 'image_mosaic/data/setting'
7
7
  require 'image_mosaic/data/validator'
8
- require 'image_mosaic/image/parent'
9
8
  require 'image_mosaic/image/child'
9
+ require 'image_mosaic/image/mosaic'
10
+ require 'image_mosaic/image/parent'
11
+ require 'image_mosaic/operations/compositor'
12
+ require 'image_mosaic/operations/construct'
13
+ require 'image_mosaic/railtie' if defined?(Rails)
10
14
 
11
15
  module ImageMosaic
12
16
  HEIGHT = 1000
13
17
  WIDTH = 1000
18
+ COLOUR = '#ffffff'.freeze
14
19
 
15
- class Construct
16
- def initialize(items)
17
- @items = items
18
- end
19
-
20
- def save
21
- parent.write("#{SecureRandom.uuid}.png")
22
- end
23
-
24
- private
25
-
26
- def parent
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)
32
- end
33
-
34
- def valid_items
35
- @valid_items ||= Data::Validator.new(@items).items
36
- end
20
+ def self.create(items, colour: COLOUR)
21
+ Operations::Construct.new(items, colour: colour).parent
37
22
  end
38
23
  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.1
4
+ version: 0.1.2
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-26 00:00:00.000000000 Z
11
+ date: 2017-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,11 +85,15 @@ files:
85
85
  - bin/setup
86
86
  - image_mosaic.gemspec
87
87
  - lib/image_mosaic.rb
88
+ - lib/image_mosaic/data/background.rb
88
89
  - lib/image_mosaic/data/setting.rb
89
90
  - lib/image_mosaic/data/validator.rb
90
91
  - lib/image_mosaic/image/child.rb
92
+ - lib/image_mosaic/image/mosaic.rb
91
93
  - lib/image_mosaic/image/parent.rb
92
94
  - lib/image_mosaic/operations/compositor.rb
95
+ - lib/image_mosaic/operations/construct.rb
96
+ - lib/image_mosaic/railtie.rb
93
97
  - lib/image_mosaic/version.rb
94
98
  homepage: http://github.com/dannyguk
95
99
  licenses: