words_to_image 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -5
- data/Rakefile +1 -1
- data/bin/words_to_image +61 -0
- data/collage.gemspec +4 -3
- data/lib/words_to_image/processor.rb +4 -2
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43c4e471e23ff83c4903aad01736bc63a8a8474d
|
4
|
+
data.tar.gz: 4684f555138e2f375d00eca16ebbfd3851796bcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8de8a6ec645815f75d5de92b67062f283ad251f0bedd74166efd768040172b6acef151e2f6a9d87f19e046252cf53cff6f5753ccc97033d46076c683b6cf9d63
|
7
|
+
data.tar.gz: c7af09a4641eecc17512a2691f275e3d4e3e950c4c6e4ff8c6018fe939d3ce76944f2e18798944d8dd4dd1f6872a7d595624743f2ba71e83e55013d243c33665
|
data/README.md
CHANGED
@@ -1,9 +1,22 @@
|
|
1
|
-
#
|
1
|
+
# Words To Image
|
2
2
|
|
3
|
-
|
3
|
+
a Ruby command line application that
|
4
|
+
|
5
|
+
* accepts a list of search keywords as arguments
|
6
|
+
* queries the Flickr API for the top-rated image for each keyword
|
7
|
+
* downloads the results
|
8
|
+
* crops them rectangularly
|
9
|
+
* assembles a collage grid from ten images and
|
10
|
+
* writes the result to a user-supplied filename
|
11
|
+
|
12
|
+
If given less than ten keywords, or if any keyword fails to
|
13
|
+
result in a match, retrieve random words from a dictionary
|
14
|
+
source such as `/usr/share/dict/words`. Repeat as necessary
|
15
|
+
until you have gathered ten images.
|
4
16
|
|
5
17
|
## Installation
|
6
|
-
|
18
|
+
[Please initially install ImageMagick](http://www.imagemagick.org/script/binary-releases.php).
|
19
|
+
|
7
20
|
Add this line to your application's Gemfile:
|
8
21
|
|
9
22
|
gem 'words_to_image'
|
@@ -16,7 +29,9 @@ Or install it yourself as:
|
|
16
29
|
|
17
30
|
$ gem install words_to_image
|
18
31
|
|
19
|
-
## Usage
|
32
|
+
## Usage Example
|
33
|
+
|
34
|
+
words_to_image --keywords="hamburg weihnachtsmarkt alster moin hafen" --result='result.jpg' --count=5 --max_width=150 --dictionary='spec/fixtures/sample_dict'
|
20
35
|
|
21
|
-
|
36
|
+
All the options are optional, just `words_to_image` would use defaults and random keywords.
|
22
37
|
|
data/Rakefile
CHANGED
data/bin/words_to_image
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'cri'
|
5
|
+
Dir.glob('lib/**/*.rb') {|file| require File.basename(file)}
|
6
|
+
|
7
|
+
command = Cri::Command.define do
|
8
|
+
name 'words_to_image'
|
9
|
+
usage 'words_to_image [options]'
|
10
|
+
summary 'A collage maker based on flickr search results'
|
11
|
+
description %q{
|
12
|
+
A command line application that:
|
13
|
+
|
14
|
+
accepts a list of search keywords as arguments,
|
15
|
+
queries the Flickr API for the top-rated image for each keyword,
|
16
|
+
downloads the results,
|
17
|
+
crops them rectangularly,
|
18
|
+
assembles a collage grid from ten images and writes the result to a user-supplied filename.
|
19
|
+
|
20
|
+
If given less than ten keywords, or if any keyword fails to
|
21
|
+
result in a match, retrieve random words from a dictionary
|
22
|
+
source such as `/usr/share/dict/words`. Repeat as necessary
|
23
|
+
until you have gathered ten images.
|
24
|
+
}
|
25
|
+
|
26
|
+
flag :h, :help, 'show help for this command' do |value, cmd|
|
27
|
+
puts cmd.help
|
28
|
+
exit 0
|
29
|
+
end
|
30
|
+
option :c, :count, 'images amount (default 10)', argument: :optional
|
31
|
+
option :d, :dictionary, 'dictionary file path', argument: :optional
|
32
|
+
option :r, :result, 'resulting collage path', argument: :optional
|
33
|
+
option :kw, :keywords, 'keywords to search for', argument: :optional
|
34
|
+
option :w, :max_width, 'max resulting file width, in px (default 750)', argument: :optional
|
35
|
+
|
36
|
+
run do |opts, args, cmd|
|
37
|
+
local_options = {
|
38
|
+
images_count: opts.fetch(:count, nil),
|
39
|
+
max_row_width: opts.fetch(:dictionary, nil),
|
40
|
+
dictionary_path: opts.fetch(:result, nil),
|
41
|
+
result_path: opts.fetch(:max_collage_width, nil)
|
42
|
+
}
|
43
|
+
keywords = opts.fetch(:keywords, "").split
|
44
|
+
|
45
|
+
begin
|
46
|
+
processor = WordsToImage::Processor.new(local_options)
|
47
|
+
|
48
|
+
puts "Fetching the top-rated images"
|
49
|
+
processor.get_images [*keywords]
|
50
|
+
|
51
|
+
puts "Downloading the images for keywords: #{processor.words.join(", ")} and creating a collage"
|
52
|
+
processor.create_collage
|
53
|
+
|
54
|
+
puts "Collage successfully created at #{processor.result_path}"
|
55
|
+
rescue => e
|
56
|
+
puts "Error while execution: #{e.message}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
command.run(ARGV)
|
data/collage.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "words_to_image"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.3"
|
8
8
|
spec.authors = ["Alona Mekhovova"]
|
9
9
|
spec.email = ["alona.tarasova@gmail.com"]
|
10
10
|
spec.summary = "A collage maker based on flickr search results"
|
@@ -27,12 +27,13 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.license = "MIT"
|
28
28
|
|
29
29
|
spec.files = `git ls-files -z`.split("\x0")
|
30
|
-
spec.executables =
|
31
|
-
spec.test_files = spec.files.grep(%r{^(
|
30
|
+
spec.executables = ["words_to_image"]
|
31
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
32
32
|
spec.require_paths = ["config", "lib/words_to_image"]
|
33
33
|
|
34
34
|
spec.add_runtime_dependency "flickraw"
|
35
35
|
spec.add_runtime_dependency "mini_magick"
|
36
|
+
spec.add_runtime_dependency "cri"
|
36
37
|
|
37
38
|
spec.add_development_dependency "bundler", "~> 1.11"
|
38
39
|
spec.add_development_dependency "rake"
|
@@ -2,11 +2,13 @@ require 'defaults'
|
|
2
2
|
|
3
3
|
module WordsToImage
|
4
4
|
class Processor
|
5
|
+
attr_reader :words, :result_path
|
6
|
+
|
5
7
|
def initialize(local_settings={})
|
6
|
-
@images_count = local_settings[:images_count] || DEFAULT_SETTINGS[:images_count]
|
8
|
+
@images_count = (local_settings[:images_count] || DEFAULT_SETTINGS[:images_count]).to_i
|
7
9
|
@dictionary_path = local_settings[:dictionary_path] || DEFAULT_SETTINGS[:dictionary_path]
|
8
10
|
@result_path = local_settings[:result_path] || DEFAULT_SETTINGS[:result_path]
|
9
|
-
@max_row_width = [local_settings[:max_row_width] || DEFAULT_SETTINGS[:max_row_width], 150].max
|
11
|
+
@max_row_width = [(local_settings[:max_row_width] || DEFAULT_SETTINGS[:max_row_width]).to_i, 150].max
|
10
12
|
|
11
13
|
@images, @words = [], []
|
12
14
|
@dictionary = Dictionary.new(@dictionary_path)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: words_to_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alona Mekhovova
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,7 +103,8 @@ description: "\n command line application that\n\n * accepts a list of sea
|
|
89
103
|
Repeat as necessary\n until you have gathered ten images.\n "
|
90
104
|
email:
|
91
105
|
- alona.tarasova@gmail.com
|
92
|
-
executables:
|
106
|
+
executables:
|
107
|
+
- words_to_image
|
93
108
|
extensions: []
|
94
109
|
extra_rdoc_files: []
|
95
110
|
files:
|
@@ -98,6 +113,7 @@ files:
|
|
98
113
|
- LICENSE.txt
|
99
114
|
- README.md
|
100
115
|
- Rakefile
|
116
|
+
- bin/words_to_image
|
101
117
|
- collage.gemspec
|
102
118
|
- config/defaults.rb
|
103
119
|
- config/flickr_init.rb
|