image_mosaic 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/image_mosaic.gemspec +36 -0
- data/lib/image_mosaic/data/validator.rb +22 -0
- data/lib/image_mosaic/image/child.rb +20 -0
- data/lib/image_mosaic/image/parent.rb +47 -0
- data/lib/image_mosaic/operations/compositor.rb +30 -0
- data/lib/image_mosaic/version.rb +3 -0
- data/lib/image_mosaic.rb +30 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 72c39930b3c7187b496a4a57b615adbd3d6d2b2f
|
4
|
+
data.tar.gz: 6aa80f9493ef2c604ca68d3a0dc2a2431fd09d1b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa1d1015f6e43dcb13da577b34663215a74ff3baeb9854641fa17d81f2d452c9832f2180f0925e05366dd38b91eea7d9233d138dc5a9ff300f575930ca18ae50
|
7
|
+
data.tar.gz: 7b6d020d22948a5e84e72c3523debdcf7dd321c74ba581f2cdea33f1a64be8b4bccf8f5160ff0da868d498dbf70941611b7227dc314704d206de7e4e40c4e5d1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Dan Goodwin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# ImageMosaic
|
2
|
+
[](https://travis-ci.org/Dannyguk/image_mosaic)
|
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.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
ImageMosaic requires ImageMagick to be installed.
|
11
|
+
|
12
|
+
OSX
|
13
|
+
|
14
|
+
$ brew install imagemagick
|
15
|
+
|
16
|
+
Linux
|
17
|
+
|
18
|
+
$ sudo apt-get install imagemagick
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'image_mosaic'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install image_mosaic
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
Create an image from an array of image URLs. The resulting image is saved to the local file system.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
images = (0..20).map { 'https://unsplash.it/200/200?random' }
|
40
|
+
mosaic = ImageMosaic::Construct.new(images)
|
41
|
+
mosaic.save
|
42
|
+
```
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dannyguk/image_mosaic.
|
47
|
+
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "image_mosaic"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'image_mosaic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "image_mosaic"
|
8
|
+
spec.version = ImageMosaic::VERSION
|
9
|
+
spec.authors = ["Dan Goodwin"]
|
10
|
+
spec.email = ["dangoodwin1@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generates a grid of images}
|
13
|
+
spec.homepage = "http://github.com/dannyguk"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_dependency "mini_magick", "~> 4.6.1"
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ImageMosaic
|
2
|
+
module Data
|
3
|
+
class Validator
|
4
|
+
def initialize(urls)
|
5
|
+
@urls = urls
|
6
|
+
end
|
7
|
+
|
8
|
+
def items
|
9
|
+
@items ||= create_images.compact
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def create_images
|
15
|
+
@urls.map do |url|
|
16
|
+
child = Image::Child.new(url)
|
17
|
+
child if child.valid?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module ImageMosaic
|
2
|
+
module Image
|
3
|
+
#Takes an array of images and metrics and then returns a single image of compisited images.
|
4
|
+
class Parent
|
5
|
+
def initialize(items, width: 1000, height: 1000, colour: 'white', columns: 5, cell_dimension: 200)
|
6
|
+
@items = items
|
7
|
+
@width = width
|
8
|
+
@height = height
|
9
|
+
@colour = colour
|
10
|
+
@columns = columns
|
11
|
+
@cell_dimension = cell_dimension
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
image.run_command(:convert, '-size', "#{@width}x#{@height}", "xc:#{@colour}", image.path)
|
16
|
+
y = 0
|
17
|
+
sliced_grid.each do |row|
|
18
|
+
x = 0
|
19
|
+
row.each do |cell|
|
20
|
+
@image = add_image(cell, x, y)
|
21
|
+
x += @cell_dimension
|
22
|
+
end
|
23
|
+
y += @cell_dimension
|
24
|
+
end
|
25
|
+
image
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def sliced_grid
|
31
|
+
@items.each_slice(@columns).to_a
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_image(child_image, x, y)
|
35
|
+
Operations::Compositor.new(@image, child_image).save(x, y, type: 'Over', dimension: @cell_dimension)
|
36
|
+
end
|
37
|
+
|
38
|
+
def temp_file
|
39
|
+
@temp_file ||= Tempfile.new(['image_mosaic', '.png'])
|
40
|
+
end
|
41
|
+
|
42
|
+
def image
|
43
|
+
@image ||= MiniMagick::Image.new(temp_file.path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ImageMosaic
|
2
|
+
module Operations
|
3
|
+
# Takes a composite_image
|
4
|
+
# Can then place another image over the top at x, y coordinates and resized to a dimension.
|
5
|
+
class Compositor
|
6
|
+
def initialize(composite_image, child)
|
7
|
+
@composite_image = composite_image
|
8
|
+
@child = child
|
9
|
+
end
|
10
|
+
|
11
|
+
def save(x, y, type: 'Over', dimension: 200)
|
12
|
+
resize_image_to(dimension)
|
13
|
+
@composite_image.composite(child_image) do |composite|
|
14
|
+
composite.compose type
|
15
|
+
composite.geometry "+#{x}+#{y}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def resize_image_to(dimension)
|
22
|
+
child_image.resize "#{dimension}x#{dimension}^"
|
23
|
+
end
|
24
|
+
|
25
|
+
def child_image
|
26
|
+
@child.image
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/image_mosaic.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "image_mosaic/version"
|
2
|
+
require 'mini_magick'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'image_mosaic/operations/compositor'
|
6
|
+
require 'image_mosaic/data/validator'
|
7
|
+
require 'image_mosaic/image/parent'
|
8
|
+
require 'image_mosaic/image/child'
|
9
|
+
|
10
|
+
module ImageMosaic
|
11
|
+
class Construct
|
12
|
+
def initialize(items)
|
13
|
+
@items = items
|
14
|
+
end
|
15
|
+
|
16
|
+
def save
|
17
|
+
parent.write("#{SecureRandom.uuid}.png")
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def parent
|
23
|
+
@parent ||= Image::Parent.new(valid_items).create
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid_items
|
27
|
+
@valid_items ||= Data::Validator.new(@items).items
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: image_mosaic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Goodwin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mini_magick
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.6.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.6.1
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- dangoodwin1@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- image_mosaic.gemspec
|
87
|
+
- lib/image_mosaic.rb
|
88
|
+
- lib/image_mosaic/data/validator.rb
|
89
|
+
- lib/image_mosaic/image/child.rb
|
90
|
+
- lib/image_mosaic/image/parent.rb
|
91
|
+
- lib/image_mosaic/operations/compositor.rb
|
92
|
+
- lib/image_mosaic/version.rb
|
93
|
+
homepage: http://github.com/dannyguk
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata:
|
97
|
+
allowed_push_host: https://rubygems.org
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.6.8
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Generates a grid of images
|
118
|
+
test_files: []
|