photomontage 0.0.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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/bg.jpg +0 -0
- data/bin/photomontage +5 -0
- data/lib/flickr.rb +74 -0
- data/lib/photomontage/version.rb +3 -0
- data/lib/photomontage.rb +61 -0
- data/photomontage.gemspec +29 -0
- data/spec/photomontage_spec.rb +11 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bb63be91d08ab59d76380c8459f7563679d5e6af
|
4
|
+
data.tar.gz: 69fad9e6672eb550f9de55781dcae607dd096253
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4931fe965a6bfc41f2afc6477b3a6bbe13a9393c58a5f26332dd2f99c83998d35c64736df222e0fd327111688d4fe7fd467e0066959eb6b15e963b5a5716750
|
7
|
+
data.tar.gz: 86dcd3ae2bc453104d58494b43b545420a8a4ae63fba57c77417fb926ae0f56fc897d6271e53df0e355c6441f708ffe0e135f604958328b1b546acbd958f2282
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2017 Aishwarya
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Photomontage
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'photomontage'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install photomontage
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/photomontage/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bg.jpg
ADDED
Binary file
|
data/bin/photomontage
ADDED
data/lib/flickr.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
class Flickr
|
2
|
+
include HTTParty
|
3
|
+
base_uri 'https://api.flickr.com'
|
4
|
+
IMAGE_WIDTH = 200
|
5
|
+
IMAGE_HEIGHT = 300
|
6
|
+
NO_IMAGES = 10
|
7
|
+
PROGRESSBAR = ProgressBar.create
|
8
|
+
|
9
|
+
def initialize(keyword, index)
|
10
|
+
call_progress_bar
|
11
|
+
@options =
|
12
|
+
{ query:
|
13
|
+
{
|
14
|
+
method: 'flickr.photos.search',
|
15
|
+
text: keyword,
|
16
|
+
sort: 'interestingness-asc',
|
17
|
+
nojsoncallback: 1,
|
18
|
+
api_key: '38f8b5be4529ce3f039a5d9b94f360cd',
|
19
|
+
per_page: 1
|
20
|
+
}
|
21
|
+
}
|
22
|
+
@index = index
|
23
|
+
@keyword = keyword
|
24
|
+
end
|
25
|
+
|
26
|
+
def search
|
27
|
+
response = self.class.get("/services/rest", @options)
|
28
|
+
if response["rsp"]["stat"] == "ok"
|
29
|
+
result = set_image_url(response)
|
30
|
+
result ? result : false
|
31
|
+
else
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def fetch
|
37
|
+
File.open("tmp/#{@index}.jpg", "wb") do |f|
|
38
|
+
image = f.write HTTParty.get(@url).parsed_response
|
39
|
+
end
|
40
|
+
image = Magick::ImageList.new("tmp/#{@index}.jpg").resize_to_fill!(IMAGE_WIDTH, IMAGE_HEIGHT)
|
41
|
+
image.write("tmp/#{@index}.jpg")
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.create_collage(file_name)
|
45
|
+
result = MiniMagick::Image.new("bg.jpg")
|
46
|
+
i,y=0,0
|
47
|
+
(0..1).each do |j|
|
48
|
+
x = -200
|
49
|
+
5.times{
|
50
|
+
img = MiniMagick::Image.new("tmp/#{i}.jpg")
|
51
|
+
result = result.composite(img) do |c|
|
52
|
+
c.compose "Over"
|
53
|
+
x += 200
|
54
|
+
i += 1
|
55
|
+
c.geometry "+#{x}+#{y}"
|
56
|
+
end
|
57
|
+
}
|
58
|
+
y += 300
|
59
|
+
end
|
60
|
+
result.write "images/#{file_name}.jpg"
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def set_image_url(response)
|
66
|
+
photo = response["rsp"]["photos"]["photo"]
|
67
|
+
return false unless photo
|
68
|
+
@url = "http://farm#{photo['farm']}.staticflickr.com/#{photo['server']}/#{photo['id']}_#{photo['secret']}.jpg"
|
69
|
+
end
|
70
|
+
|
71
|
+
def call_progress_bar
|
72
|
+
5.times{PROGRESSBAR.increment; sleep 0.01}
|
73
|
+
end
|
74
|
+
end
|
data/lib/photomontage.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "photomontage/version"
|
3
|
+
require 'httparty'
|
4
|
+
require "mini_magick"
|
5
|
+
require "rmagick"
|
6
|
+
require 'ruby-progressbar'
|
7
|
+
require 'flickr'
|
8
|
+
require 'colorize'
|
9
|
+
|
10
|
+
module Photomontage
|
11
|
+
def self.begin
|
12
|
+
puts "Hi there! Welcome to".green + " Photomontage!!".bold.green + "\nSimply provide 10 or less words, and get a collage of pictures representing your words, in seconds!\n".green
|
13
|
+
puts "Type".green + " 'exit' ".red + "anytime to stop providing words \n".green
|
14
|
+
keywords = []
|
15
|
+
10.times{
|
16
|
+
word = STDIN.gets.chomp
|
17
|
+
break if word == 'exit'
|
18
|
+
keywords << word
|
19
|
+
}
|
20
|
+
respond(keywords)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.respond(keywords)
|
24
|
+
FileUtils.rm_rf(Dir.glob('tmp/*'))
|
25
|
+
puts "\nHold on...While we make your collage...\n".green
|
26
|
+
|
27
|
+
keywords.each_with_index do |keyword, index|
|
28
|
+
scrape_flickr(keyword, index)
|
29
|
+
end
|
30
|
+
verify_images_present?
|
31
|
+
puts "\n\nGreat! Your photo collage is ready! What would you like to name it?".yellow
|
32
|
+
file_name = STDIN.gets.chomp
|
33
|
+
Flickr.create_collage(file_name)
|
34
|
+
puts "\n\nDone! Type".green + " 'open images/#{file_name}.jpg' ".magenta + "to view your image now!".green
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def self.scrape_flickr(keyword, index)
|
40
|
+
flickr = Flickr.new(keyword, index)
|
41
|
+
result = flickr.search
|
42
|
+
flickr.fetch if result
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.verify_images_present?
|
46
|
+
(0..9).each do |i|
|
47
|
+
file = "tmp/#{i}.jpg"
|
48
|
+
unless File.exist?(file)
|
49
|
+
while !File.exist?(file)
|
50
|
+
result = pick_random_word(i)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.pick_random_word(i)
|
57
|
+
dictionary = File.read('/usr/share/dict/words').split("\n")
|
58
|
+
random_word = dictionary.sample
|
59
|
+
scrape_flickr(random_word, i)
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'photomontage/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "photomontage"
|
8
|
+
spec.version = Photomontage::VERSION
|
9
|
+
spec.authors = ["Aishwarya"]
|
10
|
+
spec.email = ["aishwarya923@gmail.com"]
|
11
|
+
spec.summary = %q{Photomontage - collage made from user provided keywords}
|
12
|
+
spec.description = %q{It's beautiful}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = ["photomontage"]
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "httparty"
|
25
|
+
spec.add_development_dependency "rmagick"
|
26
|
+
spec.add_development_dependency "mini_magick"
|
27
|
+
spec.add_development_dependency "ruby-progressbar"
|
28
|
+
spec.add_development_dependency "colorize"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: photomontage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aishwarya
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-20 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rmagick
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mini_magick
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: ruby-progressbar
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: colorize
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: It's beautiful
|
126
|
+
email:
|
127
|
+
- aishwarya923@gmail.com
|
128
|
+
executables:
|
129
|
+
- photomontage
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- bg.jpg
|
139
|
+
- bin/photomontage
|
140
|
+
- lib/flickr.rb
|
141
|
+
- lib/photomontage.rb
|
142
|
+
- lib/photomontage/version.rb
|
143
|
+
- photomontage.gemspec
|
144
|
+
- spec/photomontage_spec.rb
|
145
|
+
homepage: ''
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.2.2
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: Photomontage - collage made from user provided keywords
|
169
|
+
test_files:
|
170
|
+
- spec/photomontage_spec.rb
|