photomontage 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/photomontage +2 -1
- data/lib/flickr.rb +29 -13
- data/lib/photomontage/version.rb +1 -1
- data/lib/photomontage.rb +7 -7
- data/photomontage.gemspec +1 -0
- data/spec/flickr_spec.rb +48 -0
- data/spec/photomontage_spec.rb +23 -5
- metadata +18 -3
- data/bg.jpg +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f116ffe0dc8f7923602ae5adcda3f7bec0fafb2
|
4
|
+
data.tar.gz: 0918142e16589077a75c2ae2c33a8877bb57522a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba80616b815074931a11691a975f5169d053085bdd6b8b8a8286a247ff388a071734ce7b7589dec8bd3228b5180d121119555c6eca05964748ffb0a2361bf418
|
7
|
+
data.tar.gz: 027735a579b80e7793018f0897a9ebf926e5de6acf568dbee38f6cb86a47c66412de040441054a2e9a2e693c2078a4ef8b95e1365c6105090bd108a816f120e7
|
data/bin/photomontage
CHANGED
data/lib/flickr.rb
CHANGED
@@ -20,7 +20,7 @@ class Flickr
|
|
20
20
|
}
|
21
21
|
}
|
22
22
|
@index = index
|
23
|
-
@
|
23
|
+
@url = nil
|
24
24
|
end
|
25
25
|
|
26
26
|
def search
|
@@ -34,6 +34,7 @@ class Flickr
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def fetch
|
37
|
+
return false unless @url
|
37
38
|
File.open("tmp/#{@index}.jpg", "wb") do |f|
|
38
39
|
image = f.write HTTParty.get(@url).parsed_response
|
39
40
|
end
|
@@ -42,26 +43,41 @@ class Flickr
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def self.create_collage(file_name)
|
45
|
-
|
46
|
+
bg_image = read_bg_image
|
47
|
+
result = loop_images(bg_image)
|
48
|
+
|
49
|
+
write_image_to_file(result, file_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def self.write_image_to_file(result, file_name)
|
55
|
+
Dir.mkdir 'images' unless File.exists?('images')
|
56
|
+
result.write "images/#{file_name}.jpg"
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.loop_images(bg_image)
|
46
60
|
i,y=0,0
|
47
61
|
(0..1).each do |j|
|
48
62
|
x = -200
|
49
63
|
5.times{
|
50
64
|
img = MiniMagick::Image.new("tmp/#{i}.jpg")
|
51
|
-
result = result
|
52
|
-
c.compose "Over"
|
53
|
-
x += 200
|
54
|
-
i += 1
|
55
|
-
c.geometry "+#{x}+#{y}"
|
56
|
-
end
|
65
|
+
result = make_composite_image(result, img, x, y, i)
|
57
66
|
}
|
58
|
-
|
67
|
+
y += 300
|
59
68
|
end
|
60
|
-
|
61
|
-
result.write "images/#{file_name}.jpg"
|
69
|
+
result
|
62
70
|
end
|
63
71
|
|
64
|
-
|
72
|
+
def self.make_composite_image(result, img, x, y, i)
|
73
|
+
result.composite(img) do |c|
|
74
|
+
c.compose "Over"
|
75
|
+
x += 200
|
76
|
+
i += 1
|
77
|
+
c.geometry "+#{x}+#{y}"
|
78
|
+
end
|
79
|
+
result
|
80
|
+
end
|
65
81
|
|
66
82
|
def set_image_url(response)
|
67
83
|
photo = response["rsp"]["photos"]["photo"]
|
@@ -77,6 +93,6 @@ class Flickr
|
|
77
93
|
File.open("tmp/bg.jpg", "wb") do |f|
|
78
94
|
f.write HTTParty.get("https://s30.postimg.org/l9fwb3to1/image.jpg").parsed_response
|
79
95
|
end
|
80
|
-
|
96
|
+
MiniMagick::Image.new("tmp/bg.jpg")
|
81
97
|
end
|
82
98
|
end
|
data/lib/photomontage/version.rb
CHANGED
data/lib/photomontage.rb
CHANGED
@@ -6,34 +6,34 @@ require "rmagick"
|
|
6
6
|
require 'ruby-progressbar'
|
7
7
|
require 'flickr'
|
8
8
|
require 'colorize'
|
9
|
+
require './config/interaction'
|
9
10
|
|
10
11
|
module Photomontage
|
11
12
|
def self.begin
|
12
|
-
puts
|
13
|
-
puts "Type".green + " 'exit' ".red + "anytime to stop providing words \n".green
|
13
|
+
puts Interaction::WELCOME
|
14
14
|
keywords = []
|
15
15
|
10.times{
|
16
16
|
word = STDIN.gets.chomp
|
17
17
|
break if word == 'exit'
|
18
|
-
keywords << word
|
18
|
+
keywords << word if !word.empty?
|
19
19
|
}
|
20
|
-
|
20
|
+
keywords
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.respond(keywords)
|
24
24
|
Dir.mkdir 'tmp' unless File.exists?('tmp')
|
25
25
|
FileUtils.rm_rf(Dir.glob('tmp/*'))
|
26
|
-
puts
|
26
|
+
puts Interaction::IN_PROGRESS
|
27
27
|
|
28
28
|
keywords.each_with_index do |keyword, index|
|
29
29
|
scrape_flickr(keyword, index)
|
30
30
|
end
|
31
31
|
verify_images_present?
|
32
|
-
puts
|
32
|
+
puts Interaction::FILE_NAME
|
33
33
|
file_name = STDIN.gets.chomp
|
34
34
|
Flickr.create_collage(file_name)
|
35
35
|
FileUtils.rm_rf(Dir.glob('tmp/*'))
|
36
|
-
puts
|
36
|
+
puts Interaction::COMPLETE.gsub('FILE_NAME', file_name)
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
data/photomontage.gemspec
CHANGED
data/spec/flickr_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'photomontage'
|
2
|
+
require 'flickr'
|
3
|
+
|
4
|
+
describe Flickr do
|
5
|
+
describe '#search' do
|
6
|
+
context 'when invoked with a valid keyword,' do
|
7
|
+
it "call the Flickr search API, and return a true value" do
|
8
|
+
flickr = Flickr.new("apple", 1)
|
9
|
+
expect(flickr.search).to_not eq(false)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when invoked with an empty string,' do
|
14
|
+
it "call the Flickr search API, and return a false value" do
|
15
|
+
flickr = Flickr.new("", 1)
|
16
|
+
expect(flickr.search).to eq(false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#fetch' do
|
22
|
+
context 'when invoked with a valid keyword,' do
|
23
|
+
it "call the Flickr search API, and return an image" do
|
24
|
+
flickr = Flickr.new("apple", 1)
|
25
|
+
flickr.search
|
26
|
+
expect(flickr.fetch).to be_kind_of(Magick::Image)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context 'when invoked with an invalid keyword,' do
|
30
|
+
it "return false" do
|
31
|
+
flickr = Flickr.new("", 1)
|
32
|
+
flickr.search
|
33
|
+
expect(flickr.fetch).to eq(false)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.create_collage' do
|
39
|
+
context 'create a collage' do
|
40
|
+
it "and return the resultant image" do
|
41
|
+
allow(Flickr).to receive(:read_bg_image)
|
42
|
+
expect(Flickr).to receive(:loop_images)
|
43
|
+
expect(Flickr).to receive(:write_image_to_file)
|
44
|
+
res = Flickr.create_collage("test_file")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/photomontage_spec.rb
CHANGED
@@ -1,10 +1,28 @@
|
|
1
1
|
require 'photomontage'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe '.
|
5
|
-
context 'when no keywords are
|
6
|
-
it "should return
|
7
|
-
|
3
|
+
describe Photomontage do
|
4
|
+
describe '.begin' do
|
5
|
+
context 'when no keywords are entered' do
|
6
|
+
it "should return empty array" do
|
7
|
+
words = ["exit"]
|
8
|
+
words.each{|word| expect(STDIN).to receive(:gets).and_return(word)}
|
9
|
+
expect(Photomontage.begin).to eq([])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when 3 keywords are entered' do
|
14
|
+
it "should return array of the entered keywords" do
|
15
|
+
words = ["penguin", "banana", "limousine", "exit"]
|
16
|
+
words.each{|word| expect(STDIN).to receive(:gets).and_return(word)}
|
17
|
+
expect(Photomontage.begin).to eq(words - ["exit"])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when 10 keywords are entered' do
|
22
|
+
it "should return array of all entered keywords" do
|
23
|
+
words = ["penguin", "banana", "limousine", "ocean", "game of thrones", "lion", "soccer", "boat", "exit"]
|
24
|
+
words.each{|word| expect(STDIN).to receive(:gets).and_return(word)}
|
25
|
+
expect(Photomontage.begin).to eq(words - ["exit"])
|
8
26
|
end
|
9
27
|
end
|
10
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: photomontage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aishwarya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - '='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 0.8.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: safe_yaml
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.0.4
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.0.4
|
125
139
|
description: It's beautiful
|
126
140
|
email:
|
127
141
|
- aishwarya923@gmail.com
|
@@ -135,12 +149,12 @@ files:
|
|
135
149
|
- LICENSE.txt
|
136
150
|
- README.md
|
137
151
|
- Rakefile
|
138
|
-
- bg.jpg
|
139
152
|
- bin/photomontage
|
140
153
|
- lib/flickr.rb
|
141
154
|
- lib/photomontage.rb
|
142
155
|
- lib/photomontage/version.rb
|
143
156
|
- photomontage.gemspec
|
157
|
+
- spec/flickr_spec.rb
|
144
158
|
- spec/photomontage_spec.rb
|
145
159
|
homepage: ''
|
146
160
|
licenses:
|
@@ -167,4 +181,5 @@ signing_key:
|
|
167
181
|
specification_version: 4
|
168
182
|
summary: Photomontage - collage made from user provided keywords
|
169
183
|
test_files:
|
184
|
+
- spec/flickr_spec.rb
|
170
185
|
- spec/photomontage_spec.rb
|
data/bg.jpg
DELETED
Binary file
|